We have run into some trouble with unit tests for one of our products. I will give some context. We develop plug-ins for Autodesk products, which have started to use .NET 8 as of this year. Because we still need to support older versions of their software, our solution is now a hybrid solution that has to work for both .NET Framework 4.7 and .NET 8.
To do this, we recently converted all the old .NET Framework projects into SDK-style projects. We use the Directory.Build.props (see below) to distinguish between different versions of the Autodesk software, and set the correct TargetFramework.
`
false
$(MSBuildProjectDirectory)out$(MSBuildProjectName)obj
$(BaseIntermediateOutputPath)$(Configuration)
bin$(Configuration)
true
<PropertyGroup>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
<PropertyGroup>
<AcadVersion Condition="$(Configuration.Contains('2021'))">2021</AcadVersion>
<AcadVersion Condition="$(Configuration.Contains('2022'))">2022</AcadVersion>
<AcadVersion Condition="$(Configuration.Contains('2023'))">2023</AcadVersion>
<AcadVersion Condition="$(Configuration.Contains('2024'))">2024</AcadVersion>
<AcadVersion Condition="$(Configuration.Contains('2025'))">2025</AcadVersion>
</PropertyGroup>
<PropertyGroup>
<NetVersion>80</NetVersion>
<NetVersion Condition="$(Configuration.Contains('Framework'))">47</NetVersion>
<NetVersion Condition="$(Configuration.Contains('2021'))">47</NetVersion>
<NetVersion Condition="$(Configuration.Contains('2022'))">47</NetVersion>
<NetVersion Condition="$(Configuration.Contains('2023'))">47</NetVersion>
<NetVersion Condition="$(Configuration.Contains('2024'))">47</NetVersion>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Staging'))">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>STAGING;TRACE</DefineConstants>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Release'))">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(NetVersion)' == '47'">
<TargetFramework>net47</TargetFramework>
<PreBuildEvent>RD /S /Q "$(ProjectDir)obj"</PreBuildEvent>
</PropertyGroup>
<PropertyGroup Condition="'$(NetVersion)' == '80'">
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(AcadVersion)' == '2021'">
<DefineConstants>$(DefineConstants);ACAD2021</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(AcadVersion)' == '2022'">
<DefineConstants>$(DefineConstants);ACAD2022</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(AcadVersion)' == '2023'">
<DefineConstants>$(DefineConstants);ACAD2023</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(AcadVersion)' == '2024'">
<DefineConstants>$(DefineConstants);ACAD2024</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(AcadVersion)' == '2025'">
<DefineConstants>$(DefineConstants);ACAD2025</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(AcadVersion)' != ''">
<Reference Include="accoremgd">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)AcCoreMgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Acdbmgd">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)AcDbMgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="acmgd">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)AcMgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="AdWindows">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)AdWindows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Autodesk.AutoCAD.Interop">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)Autodesk.AutoCAD.Interop.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Autodesk.AutoCAD.Interop.Common">
<HintPath>..Desktop.References.AutodeskAutoCAD$(AcadVersion)Autodesk.AutoCAD.Interop.Common.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
`
This solution works functionally. We have no issues with building, debugging and deployment via Git pipelines. The issue we are having are related to unit tests. Unit tests work fine if we run them via command line, and so they work in the pipelines too.
However, via VSTest they are now broken. Which is an issue because we cannot use the debugger anymore to fix broken unit tests. Here’s an example of one of the test projects we use.
`
<PropertyGroup>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<Configurations>Debug;Release;Staging</Configurations>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="obj**" />
<EmbeddedResource Remove="obj**" />
<None Remove="obj**" />
<Page Remove="obj**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.TestPlatform" Version="17.10.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
`
The error messages provided are not helpful to me, and somewhat inconsistent.
It sometimes complains about a missing reference to System.RunTime.
It complains about a StackOverflowException (unrelated to any individual test cause it will run none).
It says ‘Reason:Could not load type ‘Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace’ from assembly ‘Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.’
The most informative to me seems “Failed to compute short-form targert framework moniker for project ‘***’ with long-form target framework moniker ””.
Strangely, one fix we found is updating the TargetFramework of the test project to net4.7. Then it does run the unit tests..
Does anyone have any idea what causes this issue and how to resolve it?
Steve_CAD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.