2012-09-10 41 views
4

不同平臺Visual Studio項目我有3個項目,配置:大廈通過的MSBuild

  • 項目A:調試| AnyCPU,發佈| AnyCPU
  • 項目B:調試| AnyCPU,發佈| AnyCPU
  • Project C:Debug | x86,Debug | x64,Release | x86,Release | x64

項目C在依賴項中有B,而在依賴項中有B。 (A < - B < - C)

我用* .bat文件,從命令行打造:

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): 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]

+1

.dll引用而不是ProjectReference是壞的,我想依賴關係也建立在每個構建。爲主項目定義'任何CPU'也是不好的,因爲它不是'任何CPU',它是x86或x64。對我而言,這個問題沒有得到很好的解決。我會評價者停止爲我的項目使用MSBuild,直到這樣做完成爲止。我想我也可以使用devenv.exe從命令行構建,但它接受這一點,不推薦使用,它是越野車,devenv有時會掛起直到無故死亡。 – watbywbarif

回答

5

我發現我的問題的解決方案。 使用在* .csproj文件中選擇元素以通過Visual Studio或通過MSBuild檢測構建,並使用MSBuild的引用(而不是ProjectReference)。

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

可以使這項工作,如果您可以在解決方案文件中定義自定義構建配置。

在Visual Studio中打開解決方案,然後打開解決方案的配置管理器。在「活動解決方案平臺」下拉列表中,將會有<New...>選項,可讓您爲該解決方案創建x86和x64平臺。創建完成後,選擇相同的下拉列表中的每一個,並確保在列表中您的項目A和B具有Any CPU,並且項目C相應地選擇了x86或x64。同時確保選中Build複選框。

現在將主動解決方案配置切換到釋放並以相同的方式定義這些額外的平臺。

你做,你就可以建立所有3個項目中的MSBuild命令行指定只是解決方案文件後:

msbuild ABC.sln /target:Build /property:Configuration=Debug;Platform=x86 /verbosity:minimal 
msbuild ABC.sln /target:Build /property:Configuration=Release;Platform=x86 /verbosity:minimal 
msbuild ABC.sln /target:Build /property:Configuration=Debug;Platform=x64 /verbosity:minimal 
msbuild ABC.sln /target:Build /property:Configuration=Release;Platform=x64 /verbosity:minimal 
0

您可以嘗試使用devenv.exe從命令行構建項目。我認爲這不會有你遇到的問題,但我記得有關這個構建選項的一些東西會被棄用,有時它會被無端掛起。我寫這個作爲一個選項,只是因爲其他兩個對我都不好。