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
218 stars 83 forks source link

MSTestAdapter fails to discover tests #80

Closed znakeeye closed 9 months ago

znakeeye commented 4 years ago

I have referenced Build nuget packages as shown below. When I try to check in, my Build dependent unit tests fail on the build server.

I don't get it. Where does this 15.1.0.0 version come from? Why can't it load the assemblies?

MSTestAdapter failed to discover tests in class 'MyTests' of assembly 'Tests.dll'. Reason Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime">
  <Version>16.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Engine" ExcludeAssets="runtime">
  <Version>16.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Locator">
  <Version>1.2.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime">
  <Version>16.3.0</Version>
</PackageReference>
malkia commented 4 years ago

I'm running into the same issue.

Forgind commented 1 year ago

15.1.0.0 is the correct version for modern MSBuild. How are you using MSBuildLocator? Was it succeeding in finding an installation with MSBuild? After the MSBuildLocator call, did you separate the MSBuild-related calls from the function that registers MSBuild?

hankovich commented 1 year ago

fixed this by adding the following

<PropertyGroup>
    <DisableMSBuildAssemblyCopyCheck>true</DisableMSBuildAssemblyCopyCheck>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" /> <!-- DO NOT UPDATE https://github.com/microsoft/MSBuildLocator/issues/210 -->
    <PackageReference Include="Microsoft.Build" Version="17.7.0" />
</ItemGroup>

to the csproj

YuliiaKovalova commented 9 months ago

The issue seems to be not relevant anymore. Feel free to reopen if you still have any concerns.