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

Aar*_*n M 28 c# msbuild asp.net-mvc

问题

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

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

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

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"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

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.

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

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

Kon*_*tin 11

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

  • 非常感谢.我添加/ p:OutputPath =\bin并且它有效. (2认同)

com*_*ech 6

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

但是,如果您的项目都构建到相同的路径而不管配置如何,这是一件非常容易的事情:在项目属性的Build选项卡中,All ConfigurationsConfiguration下拉列表中选择然后更改Output path.

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


Zin*_*nov 6

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

在此处输入图片说明