Trouble with Visual Studio test explorer in C# solution with multiple .NET versions

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?

New contributor

Steve_CAD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật