C# – Issue Building a single project using msbuild that has multiple configurations

asp.net-mvccmsbuild

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.

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.

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

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.

Best Answer

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

Related Topic