2

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>
caxapexac
  • 645
  • 6
  • 21

1 Answers1

3

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?

caxapexac
  • 645
  • 6
  • 21
  • Just FYI. Modifying `.csproj` and adding `..\..\obj\` works in my case. However, `Directory.Build.props` doesn't work. Thanks to the information [here](https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019#msbuildprojectextensionspath) – Hustlion May 10 '21 at 08:36
  • @Hustlion FYI Directory.Build.props has worked for me in the past, but I had have to restart VS after every edit. I just checked again. With VS2019, I had close and re-open the the sln for your change to BaseIntermediateOutputPath in Directory.Build.props to take effect. MS warns against the use of Directory.Build.props because it may intriduce a dependency which is not a build machine. This is why I use it, to make changes to my local .csproj such as 0 – Andrew Dennison Mar 25 '22 at 14:39