5

我正在尝试在 .Net v4.0 上进行发布和调试构建,其中我有一个 MSBuild 项目文件而不是解决方案文件。我想使用相同的构建项目文件,但只是覆盖在“调试”和“发布”之间切换的配置属性。

当我执行如下

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

我收到以下错误

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=''.

我可以看到错误发生在_CheckForInvalidConfigurationAndPlatform.

如果我传递一个 OutputPath 属性,它将起作用

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

这是一个已知的错误 ?在我需要覆盖 Configuration 属性的地方,我将被迫覆盖 OutputPath 属性,即使我不希望这样做。

提前致谢。

4

3 回答 3

4

在我的项目文件中,OutputPath 属性是在为每个配置和平台指定的属性组中定义的。如果您没有设置正确的平台,则未设置 OutputPath 属性,您的构建将失败。

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

将 Platform 属性添加到命令行中:

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj /target:rebuild "/property:Configuration=Debug;Platform=AnyCPU" /verbosity:Diagnostic
于 2012-01-09T13:13:46.230 回答
3

将以下内容之一添加到您的项目文件中。该错误意味着OutputPath环境变量没有得到它的值。通过从 PropertyGroup 中删除“Condition=”,默认情况下将始终为任何平台或配置设置 OutputPath。

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

<PropertyGroup>
    <OutputPath>$(DefaultOutputDirectory)</OutputPath>
</PropertyGroup>
于 2014-08-27T23:12:57.630 回答
2

如果您不想修改项目文件,也可以在命令中指定构建的 OutputPath:

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj /target:rebuild "/property:Configuration=Debug;OutputPath=C:\MyOutputPath" /verbosity:Diagnostic
于 2015-01-26T14:26:49.357 回答