Trouble moving bin/ and obj/ to .bin/ and .obj/
See original GitHub issueMoved 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:
- Build into
.bin
and.obj
- Ensure there are no
bin
andobj
created. - Check VS Code, VS 2017, dotnet.exe
Or my case is relevant for respecting
?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
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.
I’m going to go ahead and close this since there isn’t a defect, but the guidelines are:
<Project Sdk=...>
(This is what your first example has wrong, there should have been a warning in the build about it.)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.