WPF .Net Core 3.1 WPF 转换不顺利(有趣的问题!!)

WPF .Net Core 3.1 WPF Conversion Not going Well (Fun Quesiton!!)

我正在将 WPF 应用程序从 Framework 4.7.2 转换为 .NetCore 3.1

整个项目的所有讨论源都在这里: https://github.com/BicycleMark/LatestSweeper

我正在使用并排/相同文件夹技术,以便 Framework 和新 Core 可以使用相同的项目和子文件夹。

Sweeper.csproj SweperCore.csproj

存在于同一文件夹中

Sweeper.csproj 像以前一样编译和运行。

SweeperCore.csproj 返回:

    Severity    Code    Description Project File    Line    Suppression State
    Error   NETSDK1005  Assets file 'D:\Src\Github\Sweeper\Sweeper\obj\project.assets.json' doesn't have a target for 
'.NETCoreApp,Version=v3.1'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project.    SweeperCore C:\Program Files\dotnet\sdk.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets    234 

我检查过它与包无关,因为 csproj 没有引用任何 pkg 文件。

这是 .NetCore SweperCore.csproj 内容:

  <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWPF>true</UseWPF>
    <OutputPath>bin_core\Debug\</OutputPath>
    <IntermediateOutputPath>out_core\Debug\</IntermediateOutputPath>
  </PropertyGroup>
</Project>

这是来自 Framework 应用程序的图片:

问题:
net472 和 netcoreapp3.1 项目都使用 ./obj/ 文件夹作为中间构建文件。显然这是一个问题,如果两个项目都在 Visual Studio.

中加载

解决方案 为一个项目替换 IntermediateOutputPathBaseIntermediateOutputPath(两者都应该有效)。这将使 Visual Studio 中的并排使用成为可能。我已经克隆了您的存储库并成功构建了这两个应用程序而无需卸载其中一个。

由于必须在使用任何 Microsoft.Common 属性之前评估 BaseIntermediateOutputPath,覆盖它需要比我预期更多的工作:

修改SweeperCore.csproj如下:

删除根项目标签中的 Sdk 属性:

<Project>

添加以下 PropertyGroupImport 作为 <Project>

的前 child
<PropertyGroup>
  <BaseIntermediateOutputPath>obj_core</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Sdk="Microsoft.NET.Sdk.WindowsDesktop" Project="Sdk.props" />

添加此 PropertyGroup 以从核心应用程序中删除 net472 out/ 文件夹:

<ItemGroup>
  <Compile Remove="obj\**" />
  <EmbeddedResource Remove="obj\**" />
  <None Remove="obj\**" />
  <Page Remove="obj\**" />
</ItemGroup>

将此 Import 添加为 </Project> 之前的最后一个 child。

<Import Sdk="Microsoft.NET.Sdk.WindowsDesktop" Project="Sdk.targets" />

原始出处:https://github.com/microsoft/msbuild/issues/1603

我在 CodeProject

上的提示和技巧中编码了完整的答案

https://www.codeproject.com/Tips/5272662/Simple-Side-By-Side-Migration-Project-Template-for