通过MSBuild使用不同的平台构建Visual Studio项目 [英] Building Visual Studio project with different platforms via MSBuild
问题描述
我有3个配置项目:
- 项目A:调试| AnyCPU,发行版| AnyCPU
- 项目B:调试| AnyCPU,发行版| AnyCPU
- 项目C:Debug | x86,Debug | x64,Release | x86,Release | x64
项目C的依赖关系为B,而B的依赖关系为A. (A<-B<-C)
Project C have B in dependencies and B have A in dependencies. (A <- B <- C)
我使用* .bat文件从命令行构建它:
I use *.bat file to build its from command line:
msbuild A.csproj /target:Build /property:Configuration=Debug;Platform=AnyCPU /verbosity:minimal
msbuild A.csproj /target:Build /property:Configuration=Release;Platform=AnyCPU /verbosity:minimal<br/>
msbuild B.csproj /target:Build /property:Configuration=Debug;Platform=AnyCPU /verbosity:minimal
msbuild B.csproj /target:Build /property:Configuration=Release;Platform=AnyCPU /verbosity:minimal
msbuild C.csproj /target:Build /property:Configuration=Debug;Platform=x86 /verbosity:minimal
msbuild C.csproj /target:Build /property:Configuration=Release;Platform=x86 /verbosity:minimal
msbuild C.csproj /target:Build /property:Configuration=Debug;Platform=x64 /verbosity:minimal
msbuild C.csproj /target:Build /property:Configuration=Release;Platform=x64 /verbosity:minimal
收到错误:
C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Microsoft.Common.targets(609,5):错误:未为项目"A.csproj"设置OutputPath属性.请检查以确保为该项目指定了配置和平台的有效组合.配置=调试"平台="x86".您可能会看到此消息,因为您正尝试在没有解决方案文件的情况下构建项目,并且指定了该项目不存在的非默认配置或平台. [A.csproj] C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Microsoft.Common.targets(609,5):错误:未为项目"B.csproj"设置OutputPath属性.请检查以确保为该项目指定了配置和平台的有效组合.配置=调试"平台="x86".您可能会看到此消息,因为您正尝试在没有解决方案文件的情况下构建项目,并且指定了该项目不存在的非默认配置或平台. [B.csproj]
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(609,5): error : The OutputPath property is not set for project 'A.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x86'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [A.csproj] C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(609,5): error : The OutputPath property is not set for project 'B.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x86'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [B.csproj]
推荐答案
我找到了解决问题的方法. 使用* .csproj文件中的Choose元素通过Visual Studio或MSBuild检测建筑物,并使用Reference(而不是ProjectReference)进行MSBuild.
I found the solution for my problem. Use Choose element in *.csproj file for detect building via Visual Studio or via MSBuild and use Reference (instead of ProjectReference) for MSBuild.
<Choose>
<When Condition="'$(BuildingInsideVisualStudio)' == 'true'">
<ItemGroup>
<ProjectReference Include="A.csproj">
<Project>{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}</Project>
<Name>A</Name>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="B.csproj">
<Project>{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}</Project>
<Name>B</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
<HintPath>A.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL">
<HintPath>B.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
这篇关于通过MSBuild使用不同的平台构建Visual Studio项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!