使用msbuild从解决方案发布一个Web项目
我试图将我的解决方案中的一个Web项目部署到服务器。 我在TeamCity上使用msbuild,如下所示:
msbuild MySolution.sln /t:WebSite:Rebuild /p:DeployOnBuild=True /p:PublishProfile=Prod ...
但是,当我运行它时,即使我的WebSite
项目不依赖于它(但它依赖于解决方案中的Services
项目),msbuild仍会尝试构建我的WebService
项目。 如何只发布一个项目,也就是WebSite
?
我也尝试使用构建项目文件
msbuild WebSite/WebSite.csproj /p:DeployOnBuild=True ...
但它然后抱怨说它无法恢复软件包:
[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:TeamCitybuildAgentworkcab8a3d752df3a51.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:TeamCitybuildAgentworkcab8a3d752df3a51.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)会失败,但我从来没有听说过,也不应该发生:
[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上发表了博客。 我也在这里复制了细节,请参阅下文。
今天在twitter @ nunofcosta大致问了我一个问题:“如何从包含多个解决方案的解决方案发布一个Web项目?”
他遇到的问题是他正在从命令行构建并将以下属性传递给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项目时,它将传递到同一组属性中。 由于这个原因,当每个项目建立时,该项目的发布过程将开始,并且它将期望在文件夹* Properties PublishProfiles *中找到名为siteone - Web Deploy.pubxml的文件。 如果文件不存在,操作可能会失败。
注意:如果您有兴趣使用这种技术进行编排发布,请在查看我的意见之前先访问https://stackoverflow.com/a/14231729/105999。
那么我们如何解决这个问题呢?
我们来看一个示例(请参阅下面的链接)。 我有一个解决方案PublishOnlyOne ,包含以下项目。
ProjA有一个名为' siteone - Web Deploy '的发布配置文件,但ProjB没有。 当试图发布它时,你可以尝试下面的命令行。
msbuild.exe PublishOnlyOne.sln /p:DeployOnBuild=true /p:PublishProfile=’siteone – Web Deploy’ /p:Password=%password%
请参阅示例中的publish-sln.cmd。
如果你这样做,当ProjB构建它的时间将会失败,因为没有siteone -该项目的Web Deploy配置文件。 因此,我们无法通过DeployOnBuild。 相反,这是我们需要做的。
我编辑了ProjA并在.csproj文件的Import语句之前添加了以下属性组。
<PropertyGroup>
<DeployOnBuild Condition=" '$(DeployProjA)'!='' ">$(DeployProjA)</DeployOnBuild>
</PropertyGroup>
在这里你可以看到DeployOnBuild被设置为DeployProjA的值,只要它不是空的。 现在修改后的命令是:
msbuild.exe PublishOnlyOne.sln /p:DeployProjA=true /p:PublishProfile=’siteone – Web Deploy’ /p:Password=%password%
这里不是传递DeployOnBuild,而是传递DeployProjA,然后设置DeployOnBuild。 由于DeployOnBuild没有传递给ProjB,它不会尝试发布。
你可以在https://github.com/sayedihashimi/sayed-samples/tree/master/PublishOnlyOne找到完整的示例。
这有一个更简单的解决方案。 构建解决方案时,MSBuild支持定位单个项目。 您可以通过将项目名称放入Target参数来完成此操作。 请注意,这是您在解决方案中指定的项目的可视名称(不一定与.csproj文件的名称相同)。
注意:这里唯一需要的“技巧”是用下划线(_)替换项目名称中的点(。) 。
示例MSBuild命令行,如果您的项目名称是“Your.Project.Name”:
msbuild.exe YourSolutionName.sln /T:"Your_Poject_Name" /P:DeployOnBuild=true /P:PublishProfile=YourPublishProfile.pubxml
您也可以指定该项目的构建目标,但该解决方案中的所有项目都应该存在此目标:
msbuild.exe YourSolutionName.sln /T:"Your_Poject_Name:Rebuild" /P:DeployOnBuild=true /P:PublishProfile=YourPublishProfile.pubxml
来源
上一篇: Publish one web project from solution with msbuild
下一篇: How to automate Web Deploy of a specific Publish Profile with an MSBuild script?