【问题标题】:How can I specify exact output path for new .csproj file format? [duplicate]如何为新的 .csproj 文件格式指定确切的输出路径? [复制]
【发布时间】:2017-12-08 01:03:06
【问题描述】:

我正在尝试使用新的 .csproj 文件格式。

我希望我的项目构建到:

C:\Development\Source\DotNet\bin\x64\Debug\

但它似乎隐含地添加到路径并在以下位置构建它:

C:\Development\Source\DotNet\bin\x64\Debug\net46

有没有办法阻止它这样做?

我的项目是:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
    <Platforms>x64</Platforms>
    <ApplicationIcon />
    <OutputType>Exe</OutputType>
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>C:\Development\Source\DotNet\bin\x64\Debug\</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="AssetManagement_Gen">
      <HintPath>..\..\Development\Source\DotNet\bin\x64\Debug\AssetManagement_Gen.dll</HintPath>
    </Reference>
    <Reference Include="EXPLink">
      <HintPath>..\..\Development\Source\DotNet\bin\x64\Debug\EXPLink.dll</HintPath>
    </Reference>
    <Reference Include="IvaraCommon">
      <HintPath>..\..\Development\Source\DotNet\bin\x64\Debug\IvaraCommon.dll</HintPath>
    </Reference>
    <Reference Include="NLog">
      <HintPath>..\..\Development\Source\DotNet\bin\x64\Debug\NLog.dll</HintPath>
    </Reference>
    <Reference Include="System.Windows.Forms" />
  </ItemGroup>

</Project>

如果我在 Visual Studio 中打开它,它还会显示附加到输出路径的“net46”。

对于我的后代,&lt;OutputPath&gt;&lt;AppendTargetFrameworkToOutputPath&gt;false&lt;/AppendTargetFrameworkToOutputPath&gt; 的组合可以让您获得完全自定义的路径。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <Platforms>x64</Platforms>
    <ApplicationIcon />
    <OutputType>Exe</OutputType>
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>..\..\..\bin\$(Platform)\$(Configuration)</OutputPath>
  </PropertyGroup>

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

  <ItemGroup>
    <Reference Include="AssetManagement_Gen">
      <HintPath>$(OutDir)\AssetManagement_Gen.dll</HintPath>
    </Reference>
    <Reference Include="EXPLink">
      <HintPath>$(OutDir)\EXPLink.dll</HintPath>
    </Reference>
    <Reference Include="IvaraCommon">
      <HintPath>$(OutDir)\IvaraCommon.dll</HintPath>
    </Reference>
    <Reference Include="NLog">
      <HintPath>$(OutDir)\NLog.dll</HintPath>
    </Reference>
    <Reference Include="System.Windows.Forms" />
  </ItemGroup>

</Project>

【问题讨论】:

    标签: c# csproj


    【解决方案1】:

    我找到了以下帖子:

    https://compiledexperience.com/blog/posts/multi-targeting-output-path

    如果您想禁用此自动附加功能,例如您将只使用一个目标框架,或者您为每个框架定义不同的输出路径,那么您可以使用 AppendTargetFrameworkToOutputPath。

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netstandard1.4</TargetFramework>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
      </PropertyGroup>
    </Project>
    

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 1970-01-01
      • 2014-10-30
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      相关资源
      最近更新 更多