testing .net4.8 in VScode using dotnet CLI(使用DotNet CLI在VScode中测试.net4.8)
问题描述
我正在尝试将使用Visual Studio生成的旧的非SDK样式的mstest项目转换为仅使用Visual Studio代码的新的SDK样式项目。
我阅读并阅读了this little how-to,但这仅适用于.NET核心和更高版本;不适用于.NET框架。
我需要我的项目同时针对这两个目标。如果我这样做
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<PackageReference Include="Microsoft.VisualStudio.UnitTesting" Version="11.0.50727.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net48'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>
</Project>
并添加一些测试,如下所示
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MyTests {
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestTwoPlusTwoIsFour()
{
Assert.IsTrue(2 + 2 == 4);
}
}
}
并在我的csproj
上运行dotnet test
,然后只测试netcoreapp3.1
、net5.0
、net6.0
。net48
不会出现在我的控制台输出中的任何地方。
我需要做什么才能测试所有四个框架?
推荐答案
似乎我cannot使用dotnet test
,但需要msbuild
。(感谢您的评论,@Heinzi。)
我可以这样运行它:
"C:Program Files (x86)Microsoft Visual Studio2019EnterpriseCommon7IDEmstest.exe" /testcontainer:"$(MSBuildProjectDirectory)$(OutputPath)$(ProjectName).dll"
如果这能以某种方式incorporated into my dotnet test
call,那就太好了,这样我就不需要两个电话...
这篇关于使用DotNet CLI在VScode中测试.net4.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用DotNet CLI在VScode中测试.net4.8


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01