【.Net Core】单元测试项目的迁移

参考

将 .NET Framework 库移植到 .NET Core
从 .NET Framework 移植到 .NET Core 的概述
.NET 可移植性分析器

一、Dotnet-Try-Convert

试着用 dotnet-try-convert 转换项目,出现如下错误
在这里插入图片描述
参考GUID列表,应该是不支持测试项目直接使用该工具迁移

Visual Studio项目类型GUID的列表

在这里插入图片描述
所以比较遗憾, 不能使用该工具进行转换

二、Portability-Analyzer

使用 可移植性分析工具 分析测试项目

结果文件位于

C:\Users\xxx\Documents\Portability Analysis

测试项目可移植率
在这里插入图片描述
不支持部分细节 (有些库并不是不支持.Net Core, 而是在项目中没有在依赖中加进来所以显示不支持)
在这里插入图片描述

三、手动修改

复制原来的xx.csproj文件为xx.NetCore.csproj文件

Note: 项目下所有.cs文件在.Net Core下默认加载进项目,如果不想使用.cs则要手动移除

xx.NetCore.csproj工程结构类似如下 (修改为自己项目的配置)

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Platform Condition=" '$(Platform)' == '' ">x64</Platform>
    <RootNamespace>Esri.ArcGISEarth.Core.Tests</RootNamespace>
    <Platforms>x64</Platforms>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AssemblyName>ArcGISEarth.Core.Tests</AssemblyName>
    <IsPackable>false</IsPackable>
    <Company>ESRI</Company>
    <Copyright>Copyright © ESRI 2015-2020</Copyright>
    <Authors>ESRI</Authors>
    <Product>ArcGIS Earth</Product>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    <OutputPath>..\..\..\..\..\..\output\earth_windesktop_debug\bin\</OutputPath>
    <IntermediateOutputPath>..\..\..\..\..\..\output\intermediate\DotNet\WinDesktop\Apps\Earth\CoreTests_Debug\</IntermediateOutputPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    <OutputPath>..\..\..\..\..\..\output\earth_windesktop_release\bin\</OutputPath>
    <IntermediateOutputPath>..\..\..\..\..\..\output\intermediate\DotNet\WinDesktop\Apps\Earth\CoreTests_Release\</IntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
    <PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
    <PackageReference Include="coverlet.collector" Version="1.0.1" />
  </ItemGroup>
  
  <ItemGroup>
    <ProjectReference Include="..\ArcGISEarth.Common\ArcGISEarth.Common.NetCore.csproj" />
    <ProjectReference Include="..\ArcGISEarth.Controls\ArcGISEarth.Controls.NetCore.csproj" />
    <ProjectReference Include="..\ArcGISEarth.Core\ArcGISEarth.Core.NetCore.csproj" />
  </ItemGroup>
  
  <Import Project="..\ArcGISEarth.Tests.Shared\ArcGISEarth.Tests.Shared.projitems" Label="Shared" Condition="Exists('..\ArcGISEarth.Tests.Shared\ArcGISEarth.Tests.Shared.projitems')" />
  
  <ItemGroup>
    <Compile Remove="Properties\AssemblyInfo.cs" />
  </ItemGroup>
</Project>

详细说明
在这里插入图片描述

基本上按照这样的修改,单元测试项目就可以迁移到.Net Core

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章