2012-01-15 44 views
23

問題問題建立一個使用項目的MSBuild有多個配置

我們正在使用的配置改變我們的解決方案裏面。例如: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" 

我得到以下錯誤的單個項目

 
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沒有用於測試的配置,以及樣本庫的映射將包含在我的.sln文件中

問題

有沒有辦法解決這個問題,而無需爲每個庫項目添加這些配置?它在這裏聞起來像一個醜陋的黑客。

+0

我不知道這是否專門解決您遇到的問題但是您可能會從我的SO帖子[在此處]獲得一些有用的信息(http://stackoverflow.com/q/8334475/132599)。 – 2012-01-16 01:40:05

回答

5

不幸的是,您將不得不修改解決方案中使用的每個項目以具有相同的構建路徑。

然而,這是一個非常容易的事,如果你的項目都建立相同的路徑,無論配置:在項目屬性Build選項卡,然後從下拉ConfigurationAll Configurations然後更改Output path

這將爲項目文件中尚未存在的所有配置創建條目,併爲所有配置設置相同的輸出路徑。

2

一個簡單的解決方案是將一個新屬性添加到名爲「DeploymentConfiguration」的項目中,並讓它執行配置之間的映射。例如:

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

然後在你的MSBuild調用,傳遞

/p:DeploymentConfiguration=Test 

在你的部署MVC你會通過直接分配只是給DeploymentConfiguration配置。

2

在Release上放置不同值的OR條件以獲得您擁有的許多不同配置。

例如。

<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> 
8

會設置開關/屬性爲您工作?它會輸出一個名爲Test的目錄中的dll(我也可以使用TeamCity變量)。 鏈接到類似的問題/回答 https://stackoverflow.com/a/1083362/90033

+1

非常感謝。我添加了/ p:OutputPath = \ bin並且它工作。 – user1325696 2016-10-18 05:57:24

2

使用TFS網上我得到了同樣的錯誤,這個固定我的問題

enter image description here

相關問題