|
1 | 1 | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
2 | | - <Target Name="EnsureMSBuildAssembliesNotCopied" AfterTargets="Build" Condition="'$(DisableMSBuildAssemblyCopyCheck)' != 'true'"> |
| 2 | + <Target Name="EnsureMSBuildAssembliesNotCopied" AfterTargets="ResolvePackageAssets" Condition="'$(DisableMSBuildAssemblyCopyCheck)' != 'true'"> |
3 | 3 | <ItemGroup> |
4 | | - <MSBuildPackagesWithoutPrivateAssets |
5 | | - Include="@(PackageReference)" |
6 | | - Condition="!$([MSBuild]::ValueOrDefault('%(PackageReference.ExcludeAssets)', '').ToLower().Contains('runtime')) and |
7 | | - ( |
8 | | - '%(PackageReference.Identity)' == 'Microsoft.Build' or |
9 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Framework' or |
10 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Utilities.Core' or |
11 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Tasks.Core' or |
12 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Engine' or |
13 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Conversion.Core' or |
14 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Runtime' or |
15 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Localization' or |
16 | | - '%(PackageReference.Identity)' == 'Microsoft.Build.Engine' or |
17 | | - '%(PackageReference.Identity)' == 'Microsoft.NET.StringTools' or |
18 | | - '%(PackageReference.Identity)' == 'NuGet.Frameworks' |
19 | | - )"/> |
| 4 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build'))" /> |
| 5 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Framework'))" /> |
| 6 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Utilities.Core'))" /> |
| 7 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Tasks.Core'))" /> |
| 8 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Engine'))" /> |
| 9 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Conversion.Core'))" /> |
| 10 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Runtime'))" /> |
| 11 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Localization'))" /> |
| 12 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.Build.Engine'))" /> |
| 13 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'Microsoft.NET.StringTools'))" /> |
| 14 | + <_MSBuildAssembliesCopyLocalItems Include="@(RuntimeCopyLocalItems->WithMetadataValue('NuGetPackageId', 'NuGet.Frameworks'))" /> |
| 15 | + <MSBuildAssembliesCopyLocalItems Include="@(_MSBuildAssembliesCopyLocalItems->WithMetadataValue('CopyLocal', 'true')->WithMetadataValue('AssetType', 'runtime'))" /> |
| 16 | + <_DistinctMSBuildPackagesReferencedPoorly Include="@(MSBuildAssembliesCopyLocalItems->Metadata('NuGetPackageId')->Distinct())" /> |
20 | 17 | </ItemGroup> |
| 18 | + |
21 | 19 | <Error |
22 | | - Condition="'@(MSBuildPackagesWithoutPrivateAssets)' != ''" |
23 | | - Text="A PackageReference to Microsoft.Build.* without ExcludeAssets="runtime" exists in your project. This will cause MSBuild assemblies to be copied to your output directory, causing your application to load them at runtime. To use the copy of MSBuild registered by MSBuildLocator, set ExcludeAssets="runtime" on the MSBuild PackageReferences. To disable this check, set the property DisableMSBuildAssemblyCopyCheck=true in your project file (not recommended as you must distributed all of MSBuild + associated toolset). Package(s) referenced: @(MSBuildPackagesWithoutPrivateAssets)" /> |
| 20 | + Condition="@(_DistinctMSBuildPackagesReferencedPoorly->Count()) > 0" |
| 21 | + Code="MSBL001" |
| 22 | + Text="A PackageReference to the package '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageId)' at version '%(_DistinctMSBuildPackagesReferencedPoorly.NuGetPackageVersion)' is present in this project without ExcludeAssets="runtime" set. This can cause errors at run-time due to MSBuild assembly-loading." |
| 23 | + HelpLink="https://aka.ms/msbuild/locator/diagnostics/MSBL001" |
| 24 | + /> |
24 | 25 | </Target> |
25 | 26 | </Project> |
0 commit comments