question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trouble moving bin/ and obj/ to .bin/ and .obj/

See original GitHub issue

Moved from https://github.com/dotnet/project-system/issues/1437#issuecomment-469568035

@dzmitry-lahoda wrote:

Not sure if right thread - but some tooling is wrong…

See the line with ProjectAssetsFile? If I remove it - my csproj fails to build. Why I ever need it? My task for to build from VS 2017 and VS Code and from dotnet command line into .bin and .obj because of Unity:(. So I did it. But when VS 2017 opens solution - it generates obj. So I did fix which kinda should work. But got issues - I followed the path, and got into C:\Program Files\dotnet\sdk\2.2.102\Sdks\Microsoft.NET.Sdk\targets\ folder and into ProjectAssetsFile. So here is fix:

<Project Sdk="Microsoft.NET.Sdk">
  <!-- fixing VS 2017 bug which makes it output directory which is not requested -->
  <PropertyGroup>
    <ProjectAssetsFile>$(MSBuildProjectDirectory)\.obj\project.assets.json</ProjectAssetsFile>
  </PropertyGroup>
  <PropertyGroup>
      <PreBuildEvent>
       IF EXIST "$(MSBuildProjectDirectory)\.obj\obj" (
         rmdir "$(MSBuildProjectDirectory)\.obj\obj" /s /q
       )
       IF EXIST "$(MSBuildProjectDirectory)\obj" (
         move  "$(MSBuildProjectDirectory)\obj" "$(MSBuildProjectDirectory)\.obj"
       )
      </PreBuildEvent>
      
      <PostBuildEvent>
       IF EXIST "$(MSBuildProjectDirectory)\.obj\obj" (
         rmdir "$(MSBuildProjectDirectory)\.obj\obj" /s /q
       )
       IF EXIST "$(MSBuildProjectDirectory)\obj" (
         move  "$(MSBuildProjectDirectory)\obj" "$(MSBuildProjectDirectory)\.obj"
       )
      </PostBuildEvent>      
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <LangVersion>latest</LangVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>.bin\Debug\</OutputPath>
    <BaseIntermediateOutputPath>.obj\Debug\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>.obj\Debug\</IntermediateOutputPath>
    <BaseOutputPath>.bin\Debug\</BaseOutputPath>
    <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>.bin\Release\</OutputPath>
    <BaseIntermediateOutputPath>.obj\Release\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>.obj\Release\</IntermediateOutputPath>
    <BaseOutputPath>.bin\Release\</BaseOutputPath>
    <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="xunit" Version="$(xUnitVersion)" />
    <PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
  </ItemGroup>
  </ItemGroup>  
</Project>

There is other workaround. Very weird - depends on order of and some hacky Import declarations, but it breaks xunit runner and VS Code. Ssee lines with Microsoft.NET.Sdk:

<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>.bin\Debug\</OutputPath>
    <BaseIntermediateOutputPath>.obj\Debug\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>.obj\Debug\</IntermediateOutputPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>.bin\Release\</OutputPath>
    <BaseIntermediateOutputPath>.obj\Release\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>.obj\Release\</IntermediateOutputPath>
  </PropertyGroup>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
  <ItemGroup>
    <None Remove=".gitignore" />

    <None Remove="**/*.meta" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Buffers" Version="4.5.0" />
    <PackageReference Include="System.IO.Pipelines" Version="4.5.3" />
    <PackageReference Include="System.Memory" Version="4.5.1" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
  </ItemGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>

Does next relates dotnet/project-system#1438?

I was not able to find solution on SO.

Should I create separate issue with that with steps:

  1. Build into .bin and .obj
  2. Ensure there are no bin and obj created.
  3. Check VS Code, VS 2017, dotnet.exe

Or my case is relevant for respecting?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nguerreracommented, Mar 5, 2019

Ah, I think I see the issue with your second example outside VS: it is relying on the Configuration property being set, which will not happen until the Sdk.props import if you dotnet build the csproj instead of a sln that contains it. Likewise if your VS Code build is operating on the csproj and not a sln.

Can you try one of my two examples? They use only BaseOutputPath and BaseItermediateOutputPath and do not need to spell out different directories for Debug and Release. These will be appended to to BaseXxx as appropriate.

I am able to build this in VS, VS Code, and dotnet.

Make sure to delete any leftover obj\ and bin\ folders from failed attempts as stale assembly info in the old intermediate directory can cause duplicate assembly attribute errors.

0reactions
nguerreracommented, Mar 6, 2019

I’m going to go ahead and close this since there isn’t a defect, but the guidelines are:

  1. Do not set BaseIntermediateOutputPath after Sdk props import (or in the body of the csproj with <Project Sdk=...> (This is what your first example has wrong, there should have been a warning in the build about it.)
  2. Do not reference Configuration before the Sdk props import` (This is what your second example has wrong.)

A reasonable simplification is to always set BaseIntermediateOutputPath in Directory.Build.props. That works, keeps your project files clean and does not require subtle analysis like above to reason about.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I want to delete all bin and obj folders to force all projects to ...
1.Right click project, unload, right click again edit, go to bottom · 2.Insert <Target Name="DeleteBinObjFolders" BeforeTargets="Clean"> < ...
Read more >
How do you ignore bin and OBJ folders from a Git repository?
The .gitignore file is the appropriate way to ignore items within a git repo. This file is just a plain text list of...
Read more >
Deleting All BIN & OBJ Folders in a Visual Studio Solution
This is my way to for deleting all BIN and OBJ folders recursively. Create an empty file and name it DeleteBinObjFolders.bat; Copy-paste code...
Read more >
obj/bin folders problem - Developer Community
we have to manually deleting all bin / obj folders in project, to make it work again. Seems to be triggered when switching...
Read more >
Do you check in bin or debug folders (and dlls) into your ...
As a general rule, source control is best used for source only, and generated files are not source. There are exceptions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found