【.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

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