Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - Change NuGet's output directory for temporary files

Currently, it seems that the default behavior of a VS project is that NuGet-managed dependencies have intermediate files made by NuGet during a compile. Those files are these, in the obj folder:

enter image description here

I like being able to control the name of these output directories (as you can see with Binary and Object), and I'd like to setup my project such that the obj folder isn't used by NuGet to store these files. Is there a way to specify this at the project level or solution level? Maybe an MSBuild XML code snippet? Would be nice.

Any information would be appreciated.

like image 418
Anthony Monterrosa Avatar asked Nov 17 '25 09:11

Anthony Monterrosa


1 Answers

Is there a way to specify this at the project level or solution level? Maybe an MSBuild XML code snippet? Would be nice.

If you want to change these nuget restore files in another folder, you can try to use Directly.Build.props file to control it.

Solution

1) create a file named Directly.Build.props in your project.

enter image description here

Then add these in this file:

<Project>
  <PropertyGroup>
    <MSBuildProjectExtensionsPath>$(ProjectDir)Binary\</MSBuildProjectExtensionsPath>
  </PropertyGroup>
</Project>

Note: MSBuild Property can only be overwritten by another property. This means that you can overwrite the obj folder as a binary folder. If you want to generate two folders Binary and Object, you can try these:

a) When you try step 1 and then build your project, you can change the property to $(ProjectDir)Object\ in Directly.Build.propsfile and then rebuild again. After that, you will see both of them.

b) do a copy task and please write these in your xxxx.csproj file.

<Target Name="CopyNugetfiles" AfterTargets="Build">
    <ItemGroup>
      <MySourceFiles Include="$(ProjectDir)Binary\*.*"/>
    </ItemGroup>
      <Copy
          SourceFiles="@(MySourceFiles)"
          DestinationFolder="$(ProjectDir)Object\"/>
  </Target>

Hope it could help you.

like image 76
Mr Qian Avatar answered Nov 19 '25 22:11

Mr Qian