Sure, I was able to reproduce this by narrowing down to the following two csproj entries.
The
Sdk value, and the
UseWindowsForms value.
This adds a reference to
System.Windows.Forms for dotnet core targeting apps.
Note: In my actual test project, I no longer need a WindowsDesktop style sdk project,
so was able to get my tests working again with the latest version by reverting to a standard Sdk project.
NCrunchIssueRepro.csproj
Code:<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
</ItemGroup>
</Project>
UnitTest1.cs
Code:using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NCrunchIssueRepro
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
Setting UseWindowsForms to false allows the test runner to run, but causes the following expected errror if any code is executed that references forms.
Code:System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
File name: 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at Library.Class1.Test()
at NCrunchIssueRepro.UnitTest1.TestMethod1() in C:\Users\Stephen\source\repos\NCrunchIssueRepro\NCrunchIssueRepro\UnitTest1.cs:line 13