Completely change obj folder location in c# project

Viewed 2399

MSBuild is strange

I already tried this and another answer and I also tried this one

After that, I changed <IntermediateOutputPath> and <BaseIntermediateOutputPath> and <OutputPath> in the .csproj file but...

It keeps creating this piece of strange stuff in the old obj folder (I don't use nuget)

project.assets.json
project.nuget.cache
project.packagespec.json
...

I have already read about Visual Studio legacy workflow causes this behaviour but do any workarounds exist?

My current .csproj file:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <StartupObject>Program</StartupObject>
    <IntermediateOutputPath>..\..\obj\</IntermediateOutputPath>
    <BaseIntermediateOutputPath>..\..\obj\</BaseIntermediateOutputPath>
    <OutputPath>..\..\bin\Build\</OutputPath>
  </PropertyGroup>
  
  <ItemGroup>
    <ProjectReference Include="foo\dependency.csproj" />
  </ItemGroup>

</Project>
1 Answers

Solved by creating Directory.Build.props file in the root of project with:

<Project>
    <PropertyGroup>
        <MSBUildProjectExtensionsPath>..\..\obj\</MSBUildProjectExtensionsPath>
    </PropertyGroup>
</Project>

Very dirty and non-obvious microsoft-style hack

Found here

Is there any good .NET compiler for windows without penetrating youself?

Related