问题使用具有多个配置的msbuild构建单个项目

时间:2021-11-16 17:03:48

Issue

问题

We are using config transforms inside our solution. For example: Debug, Test, Staging, Release However, those configurations are only used on our MVC projects. all of the libraries only use Debug and Release, which makes more sense, because our libraries only need to be built in either debug mode, or release mode.

我们在解决方案中使用配置转换。例如:调试,测试,暂存,发布但是,这些配置仅用于我们的MVC项目。所有库只使用Debug和Release,这更有意义,因为我们的库只需要在调试模式或发布模式下构建。

The issue arises when attempting to build a single project from the command line. I need to be able to do this in order to auto deploy our builds from TeamCity to our testing environment.

尝试从命令行构建单个项目时会出现此问题。我需要能够这样做才能将我们的构建从TeamCity自动部署到我们的测试环境。

When I build the single project like this

当我像这样构建单个项目时

msbuild myproject.csproj 
/t:Build 
/P:Configuration=Test 
/P:Platform=AnyCPU 
/P:DeployOnBuild=True 
/P:DeployTarget=MSDeployPublish 
/P:MsDeployServiceUrl=https://SERVER:8172/MsDeploy.axd 
/P:AllowUntrustedCertificate=True 
/P:MSDeployPublishMethod=WMSvc 
/P:CreatePackageOnPublish=True 
/P:UserName=Username 
/P:Password=Passsword 
/P:DeployIisAppPath="IISAPPPATH"

I get the following error

我收到以下错误

myproject.csproj" (Build target) (1) ->
"C:\src\myproject.csproj" (default target) (18) ->
  c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9)
: error : The OutputPath property is not set for project 'sampleLibrary.csproj'.  
Please check to make sure that you have specified a valid combination of
 Configuration and Platform for this project.  Configuration='Test'
  Platform='AnyCPU'.  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.

I know what it means, because my sampleLibrary does not have a configuration for test, and the mapping for the sampleLibrary would be contained in my .sln file

我知道这意味着什么,因为我的sampleLibrary没有测试配置,sampleLibrary的映射将包含在我的.sln文件中

Question

Is there a way to resolve this without having to add those configurations for every library project? It smells like an ugly hack here.

有没有办法解决这个问题,而无需为每个库项目添加这些配置?它闻起来像一个丑陋的黑客在这里。

5 个解决方案

#1


5  

Unfortunately, you will have to modify every project that is used in the solution to have the same build path.

不幸的是,您必须修改解决方案中使用的每个项目以具有相同的构建路径。

However, this is a pretty easy thing to do if your projects all build to the same path regardless of configuration: in the project properties' Build tab, select All Configurations from the Configuration dropdown and then change the Output path.

但是,如果您的项目无论配置如何都构建到相同的路径,这是一件非常容易的事情:在项目属性的“构建”选项卡中,从“配置”下拉列表中选择“所有配置”,然后更改“输出”路径。

This will create entries for all of the configurations in the project file that do not already existing and set the same output path for all configurations.

这将为项目文件中尚未存在的所有配置创建条目,并为所有配置设置相同的输出路径。

#2


9  

Would setting the switch/property /p:OutputPath=Test work for you? It would output the dlls in a directory called Test (I guees you also could use TeamCity variables). Link to similar question/answer https://*.com/a/1083362/90033

设置开关/属性/ p:OutputPath = Test会为你工作吗?它会在名为Test的目录中输出dll(我猜你也可以使用TeamCity变量)。链接到类似的问题/答案https://*.com/a/1083362/90033

#3


3  

Using the tfs online I got the same error, this fixed my problem

使用tfs在线我得到了同样的错误,这解决了我的问题

问题使用具有多个配置的msbuild构建单个项目

#4


2  

One simple solution would be to add a new property to your projects called "DeploymentConfiguration" and have it do the mapping between configs. Example:

一个简单的解决方案是向项目中添加一个名为“DeploymentConfiguration”的新属性,并让它在配置之间进行映射。例:

  <!-- this is your non-deployment DLL -->
  <!-- Default DeploymentConfiguration to 'Debug' -->
 <DeploymentConfiguration Condition="'$(DeploymentConfiguration)'==''">Debug</DeploymentConfiguartion>
 <Configuration Condition='$(DeploymentConfiguration)'=='Test'">Debug</Configuration>

Then in your MSBuild invocation, pass in

然后在MSBuild调用中,传入

 /p:DeploymentConfiguration=Test

In your deployment MVC you'd just assign DeploymentConfiguration through to Configuration directly.

在部署MVC中,您只需将DeploymentConfiguration直接分配给Configuration。

#5


2  

Put an OR condition for the different values on Release for as many different configurations that you have.

为Release上的不同值设置OR条件,以获得您拥有的许多不同配置。

eg.

例如。

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' Or '$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

#1


5  

Unfortunately, you will have to modify every project that is used in the solution to have the same build path.

不幸的是,您必须修改解决方案中使用的每个项目以具有相同的构建路径。

However, this is a pretty easy thing to do if your projects all build to the same path regardless of configuration: in the project properties' Build tab, select All Configurations from the Configuration dropdown and then change the Output path.

但是,如果您的项目无论配置如何都构建到相同的路径,这是一件非常容易的事情:在项目属性的“构建”选项卡中,从“配置”下拉列表中选择“所有配置”,然后更改“输出”路径。

This will create entries for all of the configurations in the project file that do not already existing and set the same output path for all configurations.

这将为项目文件中尚未存在的所有配置创建条目,并为所有配置设置相同的输出路径。

#2


9  

Would setting the switch/property /p:OutputPath=Test work for you? It would output the dlls in a directory called Test (I guees you also could use TeamCity variables). Link to similar question/answer https://*.com/a/1083362/90033

设置开关/属性/ p:OutputPath = Test会为你工作吗?它会在名为Test的目录中输出dll(我猜你也可以使用TeamCity变量)。链接到类似的问题/答案https://*.com/a/1083362/90033

#3


3  

Using the tfs online I got the same error, this fixed my problem

使用tfs在线我得到了同样的错误,这解决了我的问题

问题使用具有多个配置的msbuild构建单个项目

#4


2  

One simple solution would be to add a new property to your projects called "DeploymentConfiguration" and have it do the mapping between configs. Example:

一个简单的解决方案是向项目中添加一个名为“DeploymentConfiguration”的新属性,并让它在配置之间进行映射。例:

  <!-- this is your non-deployment DLL -->
  <!-- Default DeploymentConfiguration to 'Debug' -->
 <DeploymentConfiguration Condition="'$(DeploymentConfiguration)'==''">Debug</DeploymentConfiguartion>
 <Configuration Condition='$(DeploymentConfiguration)'=='Test'">Debug</Configuration>

Then in your MSBuild invocation, pass in

然后在MSBuild调用中,传入

 /p:DeploymentConfiguration=Test

In your deployment MVC you'd just assign DeploymentConfiguration through to Configuration directly.

在部署MVC中,您只需将DeploymentConfiguration直接分配给Configuration。

#5


2  

Put an OR condition for the different values on Release for as many different configurations that you have.

为Release上的不同值设置OR条件,以获得您拥有的许多不同配置。

eg.

例如。

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' Or '$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>