0

我为 win64 和 osx-x64 开发了一个 net6 应用程序,我想将 OutputPath 设置为自定义路径。

我只从win64版本开始。我使用x64解决方案配置

这是我的 csproj :

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <AssemblyName>XXX</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>$(SolutionDir)..\output\debug64\</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutputPath>$(SolutionDir)..\output\release64\</OutputPath>
  </PropertyGroup>

然后我添加 osx 版本变成这样:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <RuntimeIdentifiers>osx-x64;win-x64</RuntimeIdentifiers>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <AssemblyName>XXX</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>$(SolutionDir)..\output\debug64\</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutputPath>$(SolutionDir)..\output\release64\</OutputPath>
  </PropertyGroup>

使用它,当我在 Mac 上编译或发布时,OutputPath 设置不正确,当我发布(使用 osx-x64)时,它会转到 bin/Release/net6/ 或 bin/Release/net6/osx-x64/publish。

我试图在 csproj 中添加它,但没有运气:

<PropertyGroup Condition="'$(Configuration)|$(Platform)|$(RuntimeIdentifier)'=='Debug|x64|osx-x64'">
    <OutputPath>$(SolutionDir)..\output\osx\debug64\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform|$(RuntimeIdentifier)'=='Release|x64|osx-x64'">
    <OutputPath>$(SolutionDir)..\output\osx\release64\</OutputPath>
</PropertyGroup>

更糟糕的是,在 Windows 上,我无法开始调试项目,有一条消息说“没有与活动解决方案配置匹配的项目配置”。在解决方案的配置管理器中,项目现在位于 AnyCPU 作为平台而不是 x64

我可以将 x64 保留为平台(对于 win 和 osx)并根据 RuntimeIdentifier 设置输出路径(如果指定)?

4

0 回答 0