問題描述
我正在嘗試將我的解決方案中的一個 Web 項目部署到服務器.我在 TeamCity 上使用 msbuild,如下所示:
I'm trying to deploy one of the web projects in my solution to a server. I am using msbuild on TeamCity like so:
msbuild MySolution.sln /t:WebSite:Rebuild /p:DeployOnBuild=True /p:PublishProfile=Prod ...
但是,當我運行它時,msbuild 仍然嘗試構建我的 WebService
項目,即使我的 WebSite
項目不依賴于它(但它確實依賴于Services
項目也在解決方案中).如何只發布一個項目,也就是 WebSite
?
However, when I run it, msbuild still tries to build my WebService
project, even though my WebSite
project does not depend on it (but it does depend on a Services
project also in the solution). How do only publish one project, aka just WebSite
?
我也嘗試過使用
msbuild WebSite/WebSite.csproj /p:DeployOnBuild=True ...
但它隨后抱怨它無法恢復包:
but it then complains that it can't restore packages:
[07:47:17]WebSiteWebSite.csproj.teamcity: Build target: Build
[07:47:17][WebSiteWebSite.csproj.teamcity] RestorePackages
[07:47:17][RestorePackages] Exec
[07:47:17][Exec] C:TeamCityuildAgentworkcab8a3d752df3a51.nugetNuGet.targets(90, 15): error MSB4064: The "LogStandardErrorAsError" parameter is not supported by the "Exec" task. Verify the parameter exists on the task, and it is a settable public instance property.
[07:47:17][Exec] C:TeamCityuildAgentworkcab8a3d752df3a51.nugetNuGet.targets(89, 9): error MSB4063: The "Exec" task could not be initialized with its input parameters.
[07:47:17][WebSiteWebSite.csproj.teamcity] Project WebSiteWebSite.csproj.teamcity failed.
當我禁用 NuGet 包還原時,CoreCompile (Csc) 失敗并出現我從未聽說過且不應該發生的錯誤:
When I disable NuGet Package Restore, CoreCompile (Csc) fails with errors I've never heard of and shouldn't be happening:
[07:54:43]WebSiteWebSite.csproj.teamcity: Build target: Build (13s)
[07:54:55][WebSiteWebSite.csproj.teamcity] CoreCompile
[07:54:55][CoreCompile] Csc
[07:54:56][Csc] AreasApiServicesTripService.cs(19, 104): error CS0241: Default parameter specifiers are not permitted
[07:54:56][Csc] HelpersStatisticsUtility.cs(11, 35): error CS1031: Type expected
[07:54:56][Csc] HelpersStatisticsUtility.cs(11, 53): error CS1002: ; expected
[07:54:56][Csc] HelpersStatisticsUtility.cs(16, 28): error CS1519: Invalid token '(' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(16, 37): error CS1519: Invalid token ',' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(17, 27): error CS1519: Invalid token '(' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(17, 32): error CS1519: Invalid token ')' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(23, 17): error CS1519: Invalid token 'for' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(23, 26): error CS1519: Invalid token '<=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(23, 45): error CS1519: Invalid token '-' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(23, 51): error CS1519: Invalid token '++' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(24, 34): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
[07:54:56][Csc] HelpersStatisticsUtility.cs(24, 37): error CS1519: Invalid token '==' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(24, 51): error CS1519: Invalid token ')' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(24, 63): error CS1519: Invalid token '++' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(25, 41): error CS1519: Invalid token '>' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(25, 53): error CS1519: Invalid token ')' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(27, 36): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(27, 48): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(28, 36): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(29, 37): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(29, 48): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
[07:54:56][Csc] HelpersStatisticsUtility.cs(29, 50): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(30, 33): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(30, 44): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
[07:54:56][Csc] HelpersStatisticsUtility.cs(30, 50): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersStatisticsUtility.cs(32, 21): error CS0116: A namespace does not directly contain members such as fields or methods
[07:54:56][Csc] HelpersStatisticsUtility.cs(35, 50): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersStatisticsUtility.cs(38, 21): error CS0116: A namespace does not directly contain members such as fields or methods
[07:54:56][Csc] HelpersStatisticsUtility.cs(40, 50): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersStatisticsUtility.cs(42, 21): error CS1022: Type or namespace definition, or end-of-file expected
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(8, 59): error CS1031: Type expected
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(8, 80): error CS1002: ; expected
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(10, 55): error CS1519: Invalid token '(' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(10, 60): error CS1520: Class, struct, or interface method must have a return type
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(10, 82): error CS1002: ; expected
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(13, 23): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(15, 60): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(18, 23): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(20, 25): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(23, 28): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(26, 28): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(29, 24): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(29, 84): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(32, 28): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(35, 9): error CS1022: Type or namespace definition, or end-of-file expected
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(23, 26): error CS0101: The namespace '<global namespace>' already contains a definition for '?'
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(26, 26): error CS0101: The namespace '<global namespace>' already contains a definition for '?'
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(29, 22): error CS0101: The namespace '<global namespace>' already contains a definition for '?'
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(29, 83): error CS0101: The namespace '<global namespace>' already contains a definition for '?'
[07:54:56][Csc] HelpersUrlHelperExtensions.cs(32, 26): error CS0101: The namespace '<global namespace>' already contains a definition for '?'
[07:54:56][Csc] ControllersSessionController.cs(13, 51): error CS0241: Default parameter specifiers are not permitted
[07:54:56][Csc] HelpersJsonNetResult.cs(13, 44): error CS1031: Type expected
[07:54:56][Csc] HelpersJsonNetResult.cs(13, 72): error CS1041: Identifier expected, 'object' is a keyword
[07:54:56][Csc] HelpersJsonNetResult.cs(13, 91): error CS1002: ; expected
[07:54:56][Csc] HelpersJsonNetResult.cs(16, 38): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(16, 59): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(17, 64): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(17, 90): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(18, 32): error CS1519: Invalid token '=' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(18, 46): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(19, 33): error CS1519: Invalid token ';' in class, struct, or interface member declaration
[07:54:56][Csc] HelpersJsonNetResult.cs(22, 23): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersJsonNetResult.cs(25, 37): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersJsonNetResult.cs(32, 23): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersJsonNetResult.cs(35, 37): error CS1518: Expected class, delegate, enum, interface, or struct
[07:54:56][Csc] HelpersJsonNetResult.cs(40, 9): error CS1022: Type or namespace definition, or end-of-file expected
[07:54:56][Csc] MailersITripMailer.cs(13, 132): error CS0241: Default parameter specifiers are not permitted
[07:54:56][Csc] MailersTripMailer.cs(54, 85): error CS0241: Default parameter specifiers are not permitted
[07:54:56][Csc] ServicesImplAuthorizationService.cs(12, 70): error CS0241: Default parameter specifiers are not permitted
[07:54:56][Csc] ServicesImplAuthorizationService.cs(43, 77): error CS0241: Default parameter specifiers are not permitted
[07:54:56][WebSiteWebSite.csproj.teamcity] Project WebSiteWebSite.csproj.teamcity failed.
推薦答案
我在 http://sedodream.com/2013/03/06/HowToPublishOneWebProjectFromASolution.aspx 幾個月前.我在這里也復制了詳細信息,請參見下文.
I blogged about this at http://sedodream.com/2013/03/06/HowToPublishOneWebProjectFromASolution.aspx a few months back. I've copied the details here as well, see below.
今天在推特上 @nunofcosta 粗略地問了我一個問題我如何從一個解決方案發布一個 Web 項目包含很多?"
Today on twitter @nunofcosta asked me roughly the question "How do I publish one web project from a solution that contains many?"
他遇到的問題是他是從命令行構建并將以下屬性傳遞給 msbuild.exe.
The issue that he is running into is that he is building from the command line and passing the following properties to msbuild.exe.
/p:DeployOnBuild=true
/p:PublishProfile='siteone - Web Deploy'
/p:Password=%password%
您可以在 http://sedodream.com/閱讀有關如何自動化發布的更多信息2013/01/06/CommandLineWebProjectPublishing.aspx.
當您將這些屬性傳遞給 msbuild.exe 時,它??們被稱為全局屬性.這些屬性很難覆蓋,并且會傳遞給構建的每個項目.因此,如果您有一個包含多個 Web 項目的解決方案,則在構建每個 Web 項目時,它會在同一組屬性中傳遞.因此,在構建每個項目時,該項目的發布過程將開始,并且它會在文件夾 *PropertiesPublishProfiles* 中找到一個名為 siteone – Web Deploy.pubxml 的文件.如果文件不存在,則操作可能會失敗.
When you pass these properties to msbuild.exe they are known as global properties. These properties are difficult to override and are passed to every project that is built. Because of this if you have a solution with multiple web projects, when each web project is built it is passed in the same set of properties. Because of this when each project is built the publish process for that project will start and it will expect to find a file named siteone – Web Deploy.pubxml in the folder *PropertiesPublishProfiles*. If the file doesn’t exist the operation may fail.
注意:如果您有興趣使用此技術進行編排發布,請參閱我在 https://stackoverflow 上的評論.com/a/14231729/105999 在這樣做之前.
Note: If you are interested in using this technique for an orchestrated publish see my comments at https://stackoverflow.com/a/14231729/105999 before doing so.
那么我們該如何解決呢?
So how can we resolve this?
讓我們看一個示例(請參閱下面的鏈接).我有一個解決方案,PublishOnlyOne,包含以下項目.
Let’s take a look at a sample (see links below). I have a solution, PublishOnlyOne, with the following projects.
- 項目
- 項目B
ProjA 有一個名為siteone – Web Deploy"的發布配置文件,ProjB 沒有.嘗試發布此內容時,您可以嘗試以下命令行.
ProjA has a publish profile named ‘siteone – Web Deploy’, ProjB does not. When trying to publish this you may try the following command line.
msbuild.exe PublishOnlyOne.sln /p:DeployOnBuild=true /p:PublishProfile=’siteone – Web Deploy’ /p:Password=%password%
請參閱示例中的 publish-sln.cmd.
如果您這樣做,那么當 ProjB 構建它的時候將失敗,因為該項目沒有 siteone – Web Deploy 配置文件.因此,我們無法通過 DeployOnBuild.相反,這是我們需要做的.
If you do this, when its time for ProjB to build it will fail because there’s no siteone – Web Deploy profile for that project. Because of this, we cannot pass DeployOnBuild. Instead here is what we need to do.
- 編輯 ProjA.csproj 以定義另一個屬性,該屬性將有條件地設置 DeployOnBuild
- 從命令行傳入該屬性
我編輯了 ProjA 并在 .csproj 文件中的 Import 語句之前添加了以下屬性組.
I edited ProjA and added the following property group before the Import statements in the .csproj file.
<PropertyGroup>
<DeployOnBuild Condition=" '$(DeployProjA)'!='' ">$(DeployProjA)</DeployOnBuild>
</PropertyGroup>
在這里您可以看到 DeployOnBuild 設置為 DeployProjA 的任何值,只要它不為空.現在修改后的命令是:
Here you can see that DeployOnBuild is set to whatever value DeployProjA is as long as it’s not empty. Now the revised command is:
msbuild.exe PublishOnlyOne.sln /p:DeployProjA=true /p:PublishProfile=’siteone – Web Deploy’ /p:Password=%password%
這里我沒有傳遞 DeployOnBuild,而是傳遞了 DeployProjA,然后它將設置 DeployOnBuild.由于 DeployOnBuild 沒有傳遞給 ProjB,它不會嘗試發布.
Here instead of passing DeployOnBuild, I pass in DeployProjA which will then set DeployOnBuild. Since DeployOnBuild wasn’t passed to ProjB it will not attempt to publish.
您可以在 https://github.com/sayedihashimi 找到完整示例/sayed-samples/tree/master/PublishOnlyOne.
這篇關于使用 msbuild 從解決方案發布一個 Web 項目的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!