2012-09-10 39 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从命令行构建项目。我认为这不会有你遇到的问题,但我记得有关这个构建选项的一些东西会被弃用,有时它会被无端挂起。我写这个作为一个选项,只是因为其他两个对我都不好。