c# - 使用具有多个配置的 msbuild 构建单个项目

标签 c# asp.net-mvc msbuild

问题

我们在我们的解决方案中使用配置转换。例如:调试、测试、暂存、发布 但是,这些配置仅用于我们的 MVC 项目。所有的库只使用 Debug 和 Release,这更有意义,因为我们的库只需要在 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"

出现以下错误

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 文件中

问题

有没有一种方法可以解决这个问题而不必为每个库项目添加这些配置?这里闻起来像一个丑陋的黑客。

最佳答案

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

关于c# - 使用具有多个配置的 msbuild 构建单个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8871200/

相关文章:

c# - Rider 没有设置我的 msbuild 变量 BuildingInsideVisualStudio

c# - 打破 POCO 关系

git - Jenkins 在 github probject 中访问 msbuild 文件

C# 和 SQL TOP 查询

c# - 编辑项目列表 c#

c# - 如何在 ASP.NET MVC 中路由 Web 表单页面?

asp.net-mvc - 没有类型为 'Blah' 的键为 'IEnumerable<SelectListItem>' 的 ViewData 项

visual-studio-2010 - 使用 msbuild 从命令提示符运行代码分析时遇到问题

c# 在运行时检查两个对象是否可比较

c# - 使用根持久类或基本持久对象是否有架构味道?