Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow certain packages in source build #5178

Merged
merged 4 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" Condition="'$(Shipping)' == 'true' AND '$(IsXPlat)' != 'true'" />
<GlobalPackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" version="1.0.0" />
<GlobalPackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" version="1.0.0" Condition=" '$(DotNetBuildFromSource)' != 'true' " />
</ItemGroup>

<ItemGroup Condition=" '$(UsePublicApiAnalyzer)' == 'true' ">
Expand All @@ -153,4 +153,36 @@
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)build\BannedSymbols.txt" Condition="'$(TestProject)' != 'true'" />
</ItemGroup>

<!-- DotNetBuildFromSource can only use packages that are open source -->
<Target Name="CheckSourceBuildPackageReferences" AfterTargets="CollectPackageReferences" Condition=" '$(DotNetBuildFromSource)' == 'true' ">
<ItemGroup>
<_allowBuildFromSourcePackage Remove="@(_allowBuildFromSourcePackage)" />
<_sourceBuildUnexpectedPackage Remove="@(_sourceBuildUnexpectedPackage)" />

<_allowBuildFromSourcePackage Include="@(PackageReference)" Condition=" '%(PackageReference.IsImplicitlyDefined)' == 'true' " />

<_allowBuildFromSourcePackage Include="Microsoft.Build.Framework" />
<_allowBuildFromSourcePackage Include="Microsoft.Build.Tasks.Core" />
<_allowBuildFromSourcePackage Include="Microsoft.Build.Utilities.Core" />
<_allowBuildFromSourcePackage Include="Microsoft.Build" />
<_allowBuildFromSourcePackage Include="Microsoft.CSharp" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.CommandLineUtils.Sources" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.FileProviders.Abstractions" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.FileSystemGlobbing" />
<_allowBuildFromSourcePackage Include="Microsoft.SourceLink.AzureRepos.Git" />
<_allowBuildFromSourcePackage Include="Microsoft.SourceLink.GitHub" />
<_allowBuildFromSourcePackage Include="Microsoft.Web.Xdt" />
<_allowBuildFromSourcePackage Include="Newtonsoft.Json" />
<_allowBuildFromSourcePackage Include="System.ComponentModel.Composition" />
<_allowBuildFromSourcePackage Include="System.Diagnostics.Debug" />
<_allowBuildFromSourcePackage Include="System.Security.Cryptography.Cng" />
<_allowBuildFromSourcePackage Include="System.Security.Cryptography.Pkcs" />
<_allowBuildFromSourcePackage Include="System.Security.Cryptography.ProtectedData" />

<_sourceBuildUnexpectedPackage Include="@(PackageReference)" Exclude="@(_allowBuildFromSourcePackage)" />
</ItemGroup>
<Error Text="Found @(_sourceBuildUnexpectedPackage-&gt;Count()) PackageReferences not on DotNetBuildFromSource allow list: '@(_sourceBuildUnexpectedPackage)'" Condition=" '@(_sourceBuildUnexpectedPackage)' != '' " />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ILMerge" PrivateAssets="All" />
<PackageReference Include="ILMerge" PrivateAssets="All" Condition=" '$(DotNetBuildFromSource)' != 'true' " />
</ItemGroup>

<ItemGroup Condition=" '$(IsCore)' == 'true' ">
Expand Down