msbuild로 웹을 게시하는 방법?
Visual Studio 2010에는 웹 응용 프로그램 프로젝트를 파일 시스템 위치에 게시 할 수있는 게시 명령이 있습니다. TeamCity 빌드 서버 에서이 작업을 수행하고 싶습니다. 따라서 솔루션 러너 또는 msbuild로 수행해야합니다. 게시 대상을 사용해 보았지만 ClickOnce에 해당되는 것으로 생각됩니다.
msbuild Project.csproj /t:Publish /p:Configuration=Deploy
기본적으로 웹 배포 프로젝트가 수행하는 작업을 정확히 수행하고 싶지만 애드 인이 없습니다. WAP를 컴파일하고 실행에 불필요한 파일을 제거하고 web.config 변환을 수행 하고 출력을 지정된 위치에 복사해야합니다.
Jeff Siver의 답변을 기반으로 한 My Solution
<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>
나는 주로 사용자 정의 msbuild 스크립트없이 작동합니다. 관련 TeamCity 빌드 구성 설정은 다음과 같습니다.
이슈 경로 : % system.teamcity.build.workingDir % \ MyProject \ obj \ Debug \ Package \ PackageTmp 러너 유형 : MSBuild (MSBuild 파일의 러너) 빌드 파일 경로 : MyProject \ MyProject.csproj 작업 디렉토리 : 체크 아웃 디렉토리와 동일 MSBuild 버전 : Microsoft .NET Framework 4.0 MSBuild 도구 버전 : 4.0 플랫폼 실행 : x86 대상 : 패키지 MSBuild.exe에 대한 명령 줄 매개 변수 : / p : Configuration = Debug
컴파일하고 (web.config 변환으로) 출력을 아티팩트로 저장합니다. 유일하게 누락 된 것은 출력을 지정된 위치로 복사하는 것입니다. 그러나 아티팩트 종속성이있는 다른 TeamCity 빌드 구성 또는 msbuild 스크립트를 사용하여 수행 할 수 있습니다.
최신 정보
다음은 컴파일하고 (web.config 변환으로) 패키지를 내 스테이징 서버로 복사하는 msbuild 스크립트입니다.
<?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)\Package\PackageTmp\**\*.*"/>
</ItemGroup>
<Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\\build02\wwwroot\$(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
Using the deployment profiles introduced in VS 2012, you can publish with the following command line:
msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=<profile-name> /p:Password=<insert-password> /p:VisualStudioVersion=11.0
For more information on the parameters see this.
I came up with such solution, works great for me:
msbuild /t:ResolveReferences;_WPPCopyWebApplication /p:BuildingProject=true;OutDir=C:\Temp\build\ Test.csproj
The secret sauce is _WPPCopyWebApplication target.
I don't know TeamCity so I hope this can work for you.
The best way I've found to do this is with MSDeploy.exe. This is part of the WebDeploy project run by Microsoft. You can download the bits here.
With WebDeploy, you run the command line
msdeploy.exe -verb:sync -source:contentPath=c:\webApp -dest:contentPath=c:\DeployedWebApp
This does the same thing as the VS Publish command, copying only the necessary bits to the deployment folder.
With VisualStudio 2012 there is a way to handle subj without publish profiles. You can pass output folder using parameters. It works both with absolute and relative path in 'publishUrl' parameter. You can use VS100COMNTOOLS, however you need to override VisualStudioVersion to use target 'WebPublish' from %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
. With VisualStudioVersion 10.0 this script will succeed with no outputs :)
Update: I've managed to use this method on a build server with just Windows SDK 7.1 installed (no Visual Studio 2010 and 2012 on a machine). But I had to follow these steps to make it work:
- Make Windows SDK 7.1 current on a machine using Simmo answer (https://stackoverflow.com/a/2907056/2164198)
- Setting Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7\10.0 to "C:\Program Files\Microsoft Visual Studio 10.0\" (use your path as appropriate)
- Copying folder %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0 from my developer machine to build server
Script:
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%
found two different solutions which worked in slightly different way:
1.이 용액 alexanderb로부터 응답 영감 [링크] . 불행히도 그것은 우리에게 효과가 없었습니다-일부 dll은 OutDir에 복사되지 않았습니다. 우리는 대체 것을 발견 ResolveReferences
으로 Build
지금 필요한 모든 파일은 OUTDIR 위치에 복사 - 대상하여 문제를 해결합니다.
msbuild / target : 빌드; _WPPCopyWebApplication / p : 구성 = 해제; 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
매개 변수는 연결 문자열이 특수 아티팩트로 처리되지 않고 올바르게 생성되도록합니다 . 자세한 정보는 링크를 참조
하십시오 .
환경을 설정해야합니다
- <웹 사이트 이름>
- <도메인>
내 블로그를 참조하십시오. (죄송한 게시물은 한국어였습니다)
- 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
이 내 배치 파일
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\Projects\testPublish\testPublish.csproj /p:DeployOnBuild=true /property:Configuration=Release
if exist "C:\PublishDirectory" rd /q /s "C:\PublishDirectory"
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\Projects\testPublish\obj\Release\Package\PackageTmp -c C:\PublishDirectory
cd C:\PublishDirectory\bin
del *.xml
del *.pdb
이것은 내 작업 배치입니다
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%
.Net Framework 폴더가 작동하지 MsBuild.exe
않기 때문에 Visual Studio를 서버에 설치하여 실행할 수 MsBuild.exe
있습니다.
공개 출력을 생성하려면 하나 이상의 매개 변수를 제공하십시오. msbuild example.sln / p : publishprofile = profilename / p : deployonbuild = true / p : configuration = debug / 또는
참고URL : https://stackoverflow.com/questions/3097489/how-to-publish-web-with-msbuild
'IT story' 카테고리의 다른 글
Java Swing revalidate () vs repaint () (0) | 2020.05.06 |
---|---|
너비 속성의 CSS \ 9 (0) | 2020.05.06 |
Rails : respond_to 블록은 어떻게 작동합니까? (0) | 2020.05.06 |
Java 식별자에서 "연결 문자"란 무엇입니까? (0) | 2020.05.06 |
이미지에서 Dockerfile을 생성하는 방법은 무엇입니까? (0) | 2020.05.06 |