How to tweak the OutputPath on a Visual Studio .NEt 2005 solution  
Author Message
Edouard Mercier





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

Hello.

I know that this kind of question has already lead to much writing on this forum. I've been digging, with no luck. I explain my need.

Context and requirements

I am compiling a MS Visual Studio .NET 2005 solution on the command line via a 'msbuild.exe' call. This solution contains several C# projects, with a dependancy graph.

By default, each project output path is set via the MSBuild 'OutputPath' property, defined with the value 'bin\$(ConfigurationName)', which imposes the output artifacts to be created related to the Visual Studio C# project location on the hard disk, in the directory 'bin\Release' related to the directory containing as a child the project, in release mode.

What I need, is to set this 'OutputPath' directory on another location, dependant on the Visual Studio C# project being compiled. Let's take an concrete example.

Example

If I have two C# projects in my solution named A.csproj and B.csproj with the following folder location:
  • C:\TEST\APath\Solution.sln
  • C:\TEST\APath1\A\A.csproj
  • C:\TEST\APath2\B\B.csproj
I'd like the artifacts to be set in:
  • C:\TEMP\AnotherPath\APath1\A\A\bin\$(ConfigurationName)
  • C:\TEMP\AnotherPath\APath2\B\B\bin\$(ConfigurationName)
I'd like this to be applicable as an option, that is to say that I'd like both the default output paths to be applied if I want, and this specific output path to be applied when I need.

Constraints

  • I want to discard MSBuild post-build event copy tasks, because the default location filesystem 'C:\TEST' is very slow, and this is exactly the reason why I want to change the artifcats output directory path.
  • I need all the VS 2005 .NET C# projects post-build and pre-build targets to be able to keep on using the 'OutputPath' property with the overriden value.
Statement

Since MSBuild mechanism first evaluate the 'OutputPath' property, and that many properties (like the 'OutDir', 'BaseIntermediateOutputPath', 'TargetDir' properties) depend on its value, and that they are evaluated once for all before any target execution (which would enable to override the 'OutputPath' property), I cannot write a pre-build target that would override this property and be evaluated after the 'PropertyGroup' 'OutputPath' and before all the previously mentionned depending properties be evaluated.


If my requirements are not clear, I'm very ready to explain back another way. If someone is able to propose a solution, this would save my month! Thank you for your time and attention. I'm quite confident that MSBuild can achieve this ;->

Edouard


Visual Studio28  
 
 
Edouard Mercier





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

Hello.

Should I consider that what I need to do is impossible I'm wondering how others do this

Is it imposed that the compilation output path be only expressed either relative to the project path or fixed Can't it be computed on the fly I cannot think that what I need is not feasible. Thank you for your help.

Edouard

 
 
Sayed Ibrahim Hashimi





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

I'm not sure if I'm following you correctly but here's what I got anywayz.
In your proj file place the following before the import statement.
<PropertyGroup>
   <
UseCustomOutputPath Condition="$(UseCustomOutputPath)==''">false</UseCustomOutputPath>
</
PropertyGroup>
<
PropertyGroup Condition="$(UseCustomOutputPath)=='True'">
   <
OutputPath>$(MSBuildProjectDirectory)\Custom\bin\$(Configuration)\</OutputPath>
   <
BaseIntermediateOutputPath>$(MSBuildProjectDirectory)\Custom\obj\</BaseIntermediateOutputPath>
</
PropertyGroup>

So if you want to use the custom path pass the property UseCustomOutputPath=True from the command line (or Properties parameter for MSBuild task). In this sample I've defaulted to false so Visual Studio won't use the custom path. But if you set it to true then Visual Studio should use it. It seems like it will still make the default obj folder, but I think that is only used for refactoring, not entirely sure. Let me know if this helps.

Sayed Ibrahim Hashimi
www.sedodream.com


 
 
Edouard Mercier





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

Thank you for the answer.

Unfortunately, the way the 'OutputPath' property is computed cannot be done via a simple property statement (see my example above). Your suggestion is the one that I've been taken in the very first place.

However, I need this property to be computed through a task of my own, because it is not a simple concatenation of properties.

Can anyone please help me Am I trying to do something that cannot be done with MSBuild Depending on the answer, I will be able to do powerful things, or not...

Thank you for your time and support. Happy new year, Edouard

 
 
Edouard Mercier





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

I am very astonished that MSBuild cannot enable the developer to control the location of the output artefacts. According to me, this is a rather basic and fundatmental feature.

I'm wondering how other developers do in order to perform this. Do they perform post-build copies This is absolutely not optimal. Could someone please tell me if I intend to do is feasible This impacts a lot the way we work with our software factories...

Many thanks in advance for your help. Regards from Edouard

 
 
Sayed Ibrahim Hashimi





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

Hi,
I think I initially mis-understood your requirements. After looking into this, I determined that you can't really achieve what you want. You can override the OutputPath, and dependent properties using an a target in the InitialTargets list. But the real problem lies in dependent items such as _IntermediateOutputPathItem. You can't override these values. The only solution to this would be to create a wrapper MSBuild proj file that would use the MSBuild task to build the project. From that you can use your custom task to generate the custom OutputPath and pass that in the Properties attribute. But this is obviously not exactly what you want.

Sayed Ibrahim Hashimi
www.sedodream.com

 
 
Edouard Mercier





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

Thank you so much for this clear answer! I'm surprised and disappointed that MSBuild does not offer this feature, and I hope that this feature (which is esential according to me) will be available in forthcoming releases.

Cheers, Edouard

 
 
ChronosWS





PostPosted: Visual Studio MSBuild, How to tweak the OutputPath on a Visual Studio .NEt 2005 solution Top

I don't know if you have decided on a solution, but we had a somewhat similar situation. Out solution was to do a global rename on the $(OutDir) variable to $(xxxOutDir) in the Microsoft.Common.targets file, then add a Custom.Before.Microsoft.targets file which defines $(xxxOutDir) and takes the $(OutDir) variable and modifies it to point to the desired location. Because you are only doing global renames on the standard targets file, it is very easy to fix it up any time you upgrade your build system, and by using the custom targets file, which is automatically included by the Microsoft.Common.targets file, you don't have to pollute the originals with random code changes.

In our case we also had to modify some of the build targets for the outer (TFS) build targets, and did something similar by copying/overriding the original targets with our own in a separate project file. This seems to work quite well, and keeps the changes fairly localized. I think it's the best for a bad situation (why MS decided to make properties passed on the MSBuild command-line immutable is beyond me, since targets files may have non-trivial transformations on those parameters.)