Visual Studio 2010有一个发布命令,允许您将Web应用程序项目发布到文件系统位置。我想在我的TeamCity构建服务器上做这件事,所以我需要用解决方案运行器或msbuild来做。我尝试使用Publish目标,但我认为这可能是为ClickOnce:

msbuild Project.csproj /t:Publish /p:Configuration=Deploy

我基本上想要做一个web部署项目所做的事情,但是没有外接程序。我需要它来编译WAP,删除任何不必要的执行文件,执行任何web。配置转换,并将输出复制到指定的位置。

我的解决方案,基于杰夫·西尔弗的回答

<Target Name="Deploy">
    <MSBuild Projects="$(SolutionFile)" 
             Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package" 
             ContinueOnError="false" />
    <Exec Command="&quot;$(ProjectPath)\obj\$(Configuration)\Package\$(ProjectName).deploy.cmd&quot; /y /m:$(DeployServer) -enableRule:DoNotDeleteRule" 
          ContinueOnError="false" />
</Target>

当前回答

在VisualStudio 2012中,有一种方法可以在不发布配置文件的情况下处理subj。您可以使用参数传递输出文件夹。它既适用于'publishUrl'参数中的绝对路径,也适用于相对路径。你可以使用VS100COMNTOOLS,但是你需要覆盖VisualStudioVersion来使用%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft. webapplication .targets中的目标'WebPublish'。在VisualStudioVersion 10.0中,这个脚本将成功,没有输出:)

更新:我已经在只安装了Windows SDK 7.1的构建服务器上使用了这个方法(机器上没有Visual Studio 2010和2012)。但我必须遵循以下步骤才能让它起作用:

使用Simmo answer (https://stackoverflow.com/a/2907056/2164198)让Windows SDK 7.1在机器上运行 将注册表键HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7\10.0设置为“C:\Program Files\Microsoft VisualStudio 10.0\”(请酌情使用您的路径) 将文件夹%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0从开发人员机器复制到构建服务器

脚本:

set WORK_DIR=%~dp0
pushd %WORK_DIR%
set OUTPUTS=%WORK_DIR%..\Outputs
set CONFIG=%~1
if "%CONFIG%"=="" set CONFIG=Release
set VSTOOLS="%VS100COMNTOOLS%"
if %VSTOOLS%=="" set "PATH=%PATH%;%WINDIR%\Microsoft.NET\Framework\v4.0.30319" && goto skipvsinit
call "%VSTOOLS:~1,-1%vsvars32.bat"
if errorlevel 1 goto end
:skipvsinit
msbuild.exe Project.csproj /t:WebPublish /p:Configuration=%CONFIG% /p:VisualStudioVersion=11.0 /p:WebPublishMethod=FileSystem /p:publishUrl=%OUTPUTS%\Project
if errorlevel 1 goto end
:end
popd
exit /b %ERRORLEVEL%

其他回答

您必须设置您的环境

<网站名称> 域> <

并参考我的博客。(抱歉帖子是韩语)

http://xyz37.blog.me/50124665657 http://blog.naver.com/PostSearchList.nhn?SearchText=webdeploy&blogId=xyz37&x=25&y=7 @ECHO OFF :: http://stackoverflow.com/questions/5598668/valid-parameters-for-msdeploy-via-msbuild ::-DeployOnBuild -True :: -False :: ::-DeployTarget -MsDeployPublish :: -Package :: ::-Configuration -Name of a valid solution configuration :: ::-CreatePackageOnPublish -True :: -False :: ::-DeployIisAppPath -<Web Site Name>/<Folder> :: ::-MsDeployServiceUrl -Location of MSDeploy installation you want to use :: ::-MsDeployPublishMethod -WMSVC (Web Management Service) :: -RemoteAgent :: ::-AllowUntrustedCertificate (used with self-signed SSL certificates) -True :: -False :: ::-UserName ::-Password SETLOCAL IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727" IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v3.5" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v3.5" IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v4.0.30319" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319" SET targetFile=<web site fullPath ie. .\trunk\WebServer\WebServer.csproj SET configuration=Release SET msDeployServiceUrl=https://<domain>:8172/MsDeploy.axd SET msDeploySite="<WebSite name>" SET userName="WebDeploy" SET password=%USERNAME% SET platform=AnyCPU SET msbuild=%FXPath%\MSBuild.exe /MaxCpuCount:%NUMBER_OF_PROCESSORS% /clp:ShowCommandLine %MSBuild% %targetFile% /p:configuration=%configuration%;Platform=%platform% /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=False /p:DeployIISAppPath=%msDeploySite% /p:MSDeployPublishMethod=WMSVC /p:MsDeployServiceUrl=%msDeployServiceUrl% /p:AllowUntrustedCertificate=True /p:UserName=%USERNAME% /p:Password=%password% /p:SkipExtraFilesOnServer=True /p:VisualStudioVersion=12.0 IF NOT "%ERRORLEVEL%"=="0" PAUSE ENDLOCAL

我想出了这样的解决方案,对我来说很管用:

msbuild /t:ResolveReferences;_WPPCopyWebApplication /p:BuildingProject=true;OutDir=C:\Temp\build\ Test.csproj

秘密武器是_WPPCopyWebApplication目标。

发现了两种不同的解决方案,它们的工作方式略有不同:

1. 这个解决方案的灵感来自alexanderb的答案。不幸的是,它没有为我们工作-一些dll没有复制到OutDir。我们发现用Build target替换ResolveReferences可以解决这个问题——现在所有必要的文件都被复制到OutDir位置。 msbuild /target:Build;_WPPCopyWebApplication /p:Configuration=Release;OutDir=C:\Tmp\myApp\ myApp .csproj 这种解决方案的缺点是OutDir不仅包含要发布的文件。

2. The first solution works well but not as we expected. We wanted to have the publish functionality as it is in Visual Studio IDE - i.e. only the files which should be published will be copied into the Output directory. As it has been already mentioned first solution copies much more files into the OutDir - the website for publish is then stored in _PublishedWebsites/{ProjectName} subfolder. The following command solves this - only the files for publish will be copied to desired folder. So now you have directory which can be directly published - in comparison with the first solution you will save some space on hard drive. msbuild /target:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\Tmp\myApp\;AutoParameterizationWebConfigConnectionStrings=false MyApp.csproj AutoParameterizationWebConfigConnectionStrings=false parameter will guarantee that connection strings will not be handled as special artifacts and will be correctly generated - for more information see link.

这是我的工作批次

publish-my-website.bat

SET MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin"
SET PUBLISH_DIRECTORY="C:\MyWebsitePublished"
SET PROJECT="D:\Github\MyWebSite.csproj"


cd /d %MSBUILD_PATH%
MSBuild %PROJECT%  /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=%PUBLISH_DIRECTORY%

请注意,我在服务器上安装了Visual Studio以便能够运行MsBuild.exe,因为. net Framework文件夹中的MsBuild.exe不能工作。

为了生成发布输出,提供另一个参数。 msbuild例子。SLN /p:publishprofile=profilename /p:deployonbuild=true /p:configuration=debug/or any