Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify exact output path for new .csproj file format? [duplicate]

Tags:

c#

csproj

I'm playing around with using the new .csproj file format.

I want my project to build to:

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

But it seems to be implicitly adding to the path and building it at:

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

Is there a way to prevent it from doing that?

My project is:

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

If I open it in visual studio it also shows up with the "net46" appended to the output path.

enter image description here

For my posterity, the combination of <OutputPath> and <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> lets you get a completely custom path.

<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>
like image 949
Derek Avatar asked Jan 04 '23 02:01

Derek


1 Answers

I found the following post:

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

If you want to disable this automatic appending, for instance you’re only going to be using one target framework or you’re defining a different output path per framework then you can use AppendTargetFrameworkToOutputPath.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>
</Project>
like image 128
Derek Avatar answered Feb 03 '23 14:02

Derek