How to override a configuration property?

泪湿孤枕 提交于 2019-12-10 14:46:55

问题


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.


回答1:


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



回答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



回答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>


来源:https://stackoverflow.com/questions/8782271/how-to-override-a-configuration-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!