問題描述
Visual Studio 2010 有一個發布命令,允許您將 Web 應用程序項目發布到文件系統位置.我想在我的 TeamCity 構建服務器上執行此操作,因此我需要使用解決方案運行程序或 msbuild 執行此操作.我嘗試使用 Publish 目標,但我認為這可能適用于 ClickOnce:
msbuild Project.csproj/t:Publish/p:Configuration=Deploy
我基本上想做一個 Web 部署項目所做的事情,但沒有插件.我需要它來編譯 WAP,刪除任何不需要執行的文件,執行任何 web.xml 文件.配置轉換,并將輸出復制到指定位置.
我的解決方案,基于 Jeff Siver 的回答
<Target Name="Deploy"><MSBuild Projects="$(SolutionFile)"屬性="配置=$(配置);DeployOnBuild=true;DeployTarget=Package"ContinueOnError="假"/><Exec Command=""$(ProjectPath)obj$(Configuration)Package$(ProjectName).deploy.cmd"/y/m:$(DeployServer) -enableRule:DoNotDeleteRule"ContinueOnError="假"/></目標>
我得到它主要是在沒有自定義 msbuild 腳本的情況下工作.以下是相關的 TeamCity 構建配置設置:
<上一頁>工件路徑:%system.teamcity.build.workingDir%MyProjectobjDebugPackagePackageTmp運行器類型:MSBuild(用于 MSBuild 文件的運行器)構建文件路徑:MyProjectMyProject.csproj工作目錄:與結帳目錄相同MSBuild 版本:Microsoft .NET Framework 4.0MSBuild 工具版本:4.0運行平臺:x86目標:包MSBuild.exe 的命令行參數:/p:Configuration=Debug這將編譯、打包(使用 web.config 轉換)并將輸出保存為工件.唯一缺少的是將輸出復制到指定位置,但這可以在另一個帶有工件依賴項的 TeamCity 構建配置或使用 msbuild 腳本中完成.
更新
這是一個 msbuild 腳本,它將編譯、打包(使用 web.config 轉換)并將輸出復制到我的登臺服務器
<?xml version="1.0" encoding="utf-8" ?><Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><屬性組><配置條件="'$(Configuration)' == ''">發布</配置><解決方案名稱>我的解決方案</解決方案名稱><SolutionFile>$(SolutionName).sln</SolutionFile><項目名稱>我的項目</項目名稱><ProjectFile>$(ProjectName)$(ProjectName).csproj</ProjectFile></屬性組><目標名稱="Build" DependsOnTargets="BuildPackage;CopyOutput"/><目標名稱="BuildPackage"><MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)"/><MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)"/></目標><目標名稱="復制輸出"><項目組><PackagedFiles Include="$(ProjectName)obj$(Configuration)PackagePackageTmp***.*"/></項目組><Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\build02wwwroot$(ProjectName)$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/></目標></項目>
您還可以從 PropertyGroup 標記中刪除 SolutionName 和 ProjectName 屬性并將它們傳遞給 msbuild.
msbuild build.xml/p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject
更新 2
由于這個問題仍然有大量流量,我認為值得用我當前使用 Web 部署(也稱為 MSDeploy).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"><屬性組><配置條件="'$(Configuration)' == ''">發布</配置><ProjectFile Condition="'$(ProjectFile)' == ''">$(ProjectName)$(ProjectName).csproj</ProjectFile><DeployServiceUrl 條件="'$(DeployServiceUrl)' == ''">http://staging-server/MSDeployAgentService</DeployServiceUrl></屬性組><目標名稱="驗證屬性"><!-- 驗證我們是否具有所有必需屬性的值--><錯誤條件="'$(ProjectName)' == '' " Text="ProjectName 是必需的."/></目標><目標名稱="構建" DependsOnTargets="VerifyProperties"><!-- 使用windows身份驗證部署--><MSBuild Projects="$(ProjectFile)"屬性=配置=$(配置);MvcBuildViews=假;部署構建=真;部署目標=MSDeployPublish;CreatePackageOnPublish=真;AllowUntrustedCertificate=True;MSDeployPublishMethod=遠程代理;MsDeployServiceUrl=$(DeployServiceUrl);SkipExtraFilesOnServer=真;用戶名=;密碼=;"ContinueOnError="假"/></目標></項目>
在 TeamCity 中,我有名為 env.Configuration
、env.ProjectName
和 env.DeployServiceUrl
的參數.MSBuild 運行器具有構建文件路徑,并且參數自動傳遞(您不必在命令行參數中指定它們).
你也可以從命令行運行它:
msbuild build.xml/p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService
Visual Studio 2010 has a Publish command that allows you to publish your Web Application Project to a file system location. I'd like to do this on my TeamCity build server, so I need to do it with the solution runner or msbuild. I tried using the Publish target, but I think that might be for ClickOnce:
msbuild Project.csproj /t:Publish /p:Configuration=Deploy
I basically want to do exactly what a web deployment project does, but without the add-in. I need it to compile the WAP, remove any files unnecessary for execution, perform any web.config transformations, and copy the output to a specified location.
My Solution, based on Jeff Siver's answer
<Target Name="Deploy">
<MSBuild Projects="$(SolutionFile)"
Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package"
ContinueOnError="false" />
<Exec Command=""$(ProjectPath)obj$(Configuration)Package$(ProjectName).deploy.cmd" /y /m:$(DeployServer) -enableRule:DoNotDeleteRule"
ContinueOnError="false" />
</Target>
I got it mostly working without a custom msbuild script. Here are the relevant TeamCity build configuration settings:
Artifact paths: %system.teamcity.build.workingDir%MyProjectobjDebugPackagePackageTmp Type of runner: MSBuild (Runner for MSBuild files) Build file path: MyProjectMyProject.csproj Working directory: same as checkout directory MSBuild version: Microsoft .NET Framework 4.0 MSBuild ToolsVersion: 4.0 Run platform: x86 Targets: Package Command line parameters to MSBuild.exe: /p:Configuration=Debug
This will compile, package (with web.config transformation), and save the output as artifacts. The only thing missing is copying the output to a specified location, but that could be done either in another TeamCity build configuration with an artifact dependency or with an msbuild script.
Update
Here is an msbuild script that will compile, package (with web.config transformation), and copy the output to my staging server
<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<SolutionName>MySolution</SolutionName>
<SolutionFile>$(SolutionName).sln</SolutionFile>
<ProjectName>MyProject</ProjectName>
<ProjectFile>$(ProjectName)$(ProjectName).csproj</ProjectFile>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="BuildPackage;CopyOutput" />
<Target Name="BuildPackage">
<MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)" />
<MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)" />
</Target>
<Target Name="CopyOutput">
<ItemGroup>
<PackagedFiles Include="$(ProjectName)obj$(Configuration)PackagePackageTmp***.*"/>
</ItemGroup>
<Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\build02wwwroot$(ProjectName)$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
You can also remove the SolutionName and ProjectName properties from the PropertyGroup tag and pass them to msbuild.
msbuild build.xml /p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject
Update 2
Since this question still gets a good deal of traffic, I thought it was worth updating my answer with my current script that uses Web Deploy (also known as MSDeploy).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<ProjectFile Condition=" '$(ProjectFile)' == '' ">$(ProjectName)$(ProjectName).csproj</ProjectFile>
<DeployServiceUrl Condition=" '$(DeployServiceUrl)' == '' ">http://staging-server/MSDeployAgentService</DeployServiceUrl>
</PropertyGroup>
<Target Name="VerifyProperties">
<!-- Verify that we have values for all required properties -->
<Error Condition=" '$(ProjectName)' == '' " Text="ProjectName is required." />
</Target>
<Target Name="Build" DependsOnTargets="VerifyProperties">
<!-- Deploy using windows authentication -->
<MSBuild Projects="$(ProjectFile)"
Properties="Configuration=$(Configuration);
MvcBuildViews=False;
DeployOnBuild=true;
DeployTarget=MSDeployPublish;
CreatePackageOnPublish=True;
AllowUntrustedCertificate=True;
MSDeployPublishMethod=RemoteAgent;
MsDeployServiceUrl=$(DeployServiceUrl);
SkipExtraFilesOnServer=True;
UserName=;
Password=;"
ContinueOnError="false" />
</Target>
</Project>
In TeamCity, I have parameters named env.Configuration
, env.ProjectName
and env.DeployServiceUrl
. The MSBuild runner has the build file path and the parameters are passed automagically (you don't have to specify them in Command line parameters).
You can also run it from the command line:
msbuild build.xml /p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService
這篇關于如何使用 msbuild 發布網頁?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!