Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I relocate bin and obj folders to same folder as sln? #4787

Closed
Shadowblitz16 opened this issue Sep 24, 2021 · 13 comments
Closed

How do I relocate bin and obj folders to same folder as sln? #4787

Shadowblitz16 opened this issue Sep 24, 2021 · 13 comments

Comments

@Shadowblitz16
Copy link

How do I relocate C# bin and obj folders to same folder as sln?
No one seems to know and there is no info on the internet on how to do it with vs code.

@JoeRobich
Copy link
Member

The location of those folders can be changed in your .csproj or by adding a Directory.Build.Props alongside your .sln file.

bin folder location is controlled by the <BaseOutputPath> property.
obj folder location is controlled by the <BaseIntermediateOutputPath> property.

See https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2019 for a more complete set of msbuild properties.

Seems like this is a request for dotnet/msbuild#3497. There are some example configurations in the issue, but maybe a modified version of this one is a good starting point.

@Shadowblitz16
Copy link
Author

@JoeRobich Can you give a example when I do this I get warnings.
Something like I set the path after the compiler.

@vzarytovskii
Copy link
Member

@JoeRobich Can you give a example when I do this I get warnings.
Something like I set the path after the compiler.

You can set it in your project file (you can specify relative path using $(MSBuildThisFileDirectory)).
Example syntax is <BaseOutputPath>$(MSBuildThisFileDirectory)..\</BaseOutputPath>, same with <BaseIntermediateOutputPath>, and <OutputPath>
For example, if you know that solution file is one level above your project file, then it should be something like:

<PropertyGroup>
	<OutputPath>$(MSBuildThisFileDirectory)..\..\</OutputPath>
</PropertyGroup>

This will set the output to directory above the project file.

If you need to set it for all projects, then you'll either need to specify it in each project, or use Directory.build.props

@Shadowblitz16
Copy link
Author

@vzarytovskii
but it gives a MSB3539 warning.

@vzarytovskii
Copy link
Member

vzarytovskii commented Sep 24, 2021

Hm, it seems to be a known issue:

dotnet/msbuild#4881

Which one of the properties are you setting? And where (in project file or props file)?

@Shadowblitz16
Copy link
Author

I was setting it here..

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

  <ItemGroup>
    <ProjectReference Include="..\PureEngine\PureEngine.csproj"/>
  </ItemGroup>

  <PropertyGroup>
    tried here
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    tried here
  </PropertyGroup>

</Project>

@vzarytovskii
Copy link
Member

I was setting it here..

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



  <ItemGroup>

    <ProjectReference Include="..\PureEngine\PureEngine.csproj"/>

  </ItemGroup>



  <PropertyGroup>

    tried here

    <OutputType>Exe</OutputType>

    <TargetFramework>net5.0</TargetFramework>

    tried here

  </PropertyGroup>



</Project>

Ok, so it looks like it's a csproj file, which one of the three properties were you trying to set? Have you tried OutputPath? Did it not work either?

@Shadowblitz16
Copy link
Author

BaseIntermediateOutputPath and OutputPath

@vzarytovskii
Copy link
Member

BaseIntermediateOutputPath and OutputPath

Does the warning persist if you'll leave only the second one?

@StingyJack
Copy link

How do I relocate C# bin and obj folders to same folder as sln?

@Shadowblitz16 - Why would you want to relocate the obj folder? If you have multiple projects in the solution and more than one of them is using that same path for obj folder, you cant be sure that what you get as a result is correct, even if it is able to compile. Making the obj folder shareable or common is not going to speed anything up, and is just an open invitation for strange and inconsistent program behavior.

For the bin folder, its going to be easier to have a post build event that copies the files from the default OutputPaths to where you need them. Thats not an uncommon thing to do, and was kind of the default behavior for TFS build's circa 2008-ish (which was actually a real pain because the programs' files would have to be re-staged into the correct directory structure before publishing).

@Shadowblitz16
Copy link
Author

BaseIntermediateOutputPath and OutputPath

Does the warning persist if you'll leave only the second one?

idk I know I messed with it for a day and couldn't get it to work. so yes most likely

How do I relocate C# bin and obj folders to same folder as sln?

@Shadowblitz16 - Why would you want to relocate the obj folder? If you have multiple projects in the solution and more than one of them is using that same path for obj folder, you cant be sure that what you get as a result is correct, even if it is able to compile. Making the obj folder shareable or common is not going to speed anything up, and is just an open invitation for strange and inconsistent program behavior.

For the bin folder, its going to be easier to have a post build event that copies the files from the default OutputPaths to where you need them. Thats not an uncommon thing to do, and was kind of the default behavior for TFS build's circa 2008-ish (which was actually a real pain because the programs' files would have to be re-staged into the correct directory structure before publishing).

I wanted the output to be in one place.

@StingyJack
Copy link

I wanted the output to be in one place.

@Shadowblitz16 - The obj folder is not output. Dont treat it as anything other than wholly disposable and useless as soon as the primary output is created.

If you are still having a problem with pointing to a common bin folder, make sure you dont have parallel builds happening and that the project dependencies are set correctly. If all that has been tried, just use a post build script for the last project in the build sequence that copies the files to the target output location.

@JoeRobich
Copy link
Member

Closing due to lack of activity.

@JoeRobich JoeRobich closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants