MSBuildLocator
MSBuildLocator copied to clipboard
MSTestAdapter fails to discover tests
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>
I'm running into the same issue.
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?
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
The issue seems to be not relevant anymore. Feel free to reopen if you still have any concerns.