Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override a configuration property?

Tags:

msbuild-4.0

I am trying to do both Release and Debug builds on .Net v4.0, where I have a MSBuild project file rather than a solution file. I want to use the same build project file, but just override the Configuration property switching between "Debug" and "Release".

When I execute as follows

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj
/target:rebuild "/property:Configuration=Debug" /verbosity:Diagnostic

I get the following error

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9):
error : The OutputPath property is not set for project
'buildinv.proj'.  Please check to make sure that you have specified a
valid combination of Configuration and Platform for this project. 
Configuration='Debug'  Platform=''.

I can see that that the error is occurring in _CheckForInvalidConfigurationAndPlatform.

If I pass an OutputPath property it will however work

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj
/target:rebuild "/property:Configuration=Debug" "/property:OutputPath=."

Is this a known bug ? Where I need to override the Configuration property I am going to get forced to override the OutputPath property even though i do not wish to.

Thanks in advance.

like image 938
pmcgrath Avatar asked Jan 08 '12 23:01

pmcgrath


3 Answers

In my project files OutputPath property is defined in the property groups specified for every Configuration & Platform. If you don't set correct Platform, OutputPath property is not set and your build will fail.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>bin\Release\</OutputPath>
</PropertyGroup>

Add Platform property into your command line:

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj /target:rebuild "/property:Configuration=Debug;Platform=AnyCPU" /verbosity:Diagnostic
like image 70
Ludwo Avatar answered Oct 01 '22 02:10

Ludwo


Add one of the following to your project file. The error means OutputPath environment variable is not getting it's value. By removing the "Condition=" from PropertyGroup, OutputPath will always be set for any platform or configuration, by default.

<PropertyGroup>
  <OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>

<PropertyGroup>
    <OutputPath>$(DefaultOutputDirectory)</OutputPath>
</PropertyGroup>
like image 29
user1026235 Avatar answered Oct 01 '22 04:10

user1026235


If you don't want to modify the project file, you can also just specify the OutputPath for the build in your command:

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj /target:rebuild "/property:Configuration=Debug;OutputPath=C:\MyOutputPath" /verbosity:Diagnostic
like image 36
grenade Avatar answered Oct 01 '22 02:10

grenade