5

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.

jww
  • 97,681
  • 90
  • 411
  • 885
pmcgrath
  • 823
  • 2
  • 9
  • 21
  • Did you manage to find a way around this? i'm sitting with the same problem, when my solution calls 19 project files, and they all default to Debug anycpu, even though I'm setting it to release on the solution – Steven Dall Jul 30 '13 at 09:18

3 Answers3

4

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
Ludwo
  • 6,043
  • 4
  • 32
  • 48
  • I already tried that but still get the same error. By not passing the Configuration or Platform I beleive it defaults back to Debug and AnyCPU respectively for projects created with VS – pmcgrath Jan 09 '12 at 14:02
  • He's using MSBuild from the command line. He's not modifying project files under a text editor. – jww Oct 24 '15 at 01:11
3

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>
2

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
grenade
  • 31,451
  • 23
  • 97
  • 126