microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
220 stars 83 forks source link

Is it safe to use ExcludeAssets="runtime;contentfiles"? #89

Closed roberthusak closed 1 year ago

roberthusak commented 4 years ago

Hi, when I try to compile this minimalistic project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Build" Version="16.0.461" ExcludeAssets="runtime" />
    <PackageReference Include="Microsoft.Build.Runtime" Version="16.0.461" ExcludeAssets="runtime;contentfiles" />
    <PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
  </ItemGroup>
</Project>

the following build error occurs:

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: Microsoft.Build.Runtime"

It's caused by the fact that instead of specifying ExcludeAssets="runtime" I specified ExcludeAssets="runtime;contentfiles" to get rid of all the included assets as well since AFAIK they should all be present in the located MSBuild installation. The application seems to work this way well, so I just want to ask if there's any catch I'm missing or I can just ignore the error using DisableMSBuildAssemblyCopyCheck. Thanks.

rainersigwald commented 4 years ago

It is safe, and that's a good workaround. We should extend this check

https://github.com/microsoft/MSBuildLocator/blob/ed4fce73f2f946c08f7ecf6f2a9cb64b056003f5/src/MSBuildLocator/build/Microsoft.Build.Locator.targets#L7

to be "contains runtime" instead of "is".