program story

MSBuild 스크립트 및 VS2010 게시는 Web.config 변환 적용

inputbox 2020. 11. 2. 07:56
반응형

MSBuild 스크립트 및 VS2010 게시는 Web.config 변환 적용


그래서 VS 2010이 설치되어 있고 TeamCity 빌드 통합을 위해 MSBuild 스크립트를 수정하는 중입니다. 한 가지를 제외하고 모든 것이 잘 작동합니다.

빌드를 게시 할 때 만든 Web.conifg 변환 파일을 적용하고 싶다고 MSBuild에 알리려면 어떻게해야합니까?

컴파일 된 웹 사이트를 생성하는 다음이 있지만 Web.config, Web.Debug.config 및 Web.Release.config 파일 (모두 3)을 컴파일 된 출력 디렉터리에 출력합니다. 스튜디오에서 파일 시스템에 게시를 수행하면 변환을 수행하고 적절한 변경 사항으로 Web.config 만 출력합니다.

<Target Name="CompileWeb">
    <MSBuild Projects="myproj.csproj" Properties="Configuration=Release;" />
</Target>

<Target Name="PublishWeb" DependsOnTargets="CompileWeb">
    <MSBuild Projects="myproj.csproj"
    Targets="ResolveReferences;_CopyWebApplication"
    Properties="WebProjectOutputDir=$(OutputFolder)$(WebOutputFolder);
                OutDir=$(TempOutputFolder)$(WebOutputFolder)\;Configuration=Release;" />
</Target>

어떤 도움이라도 좋을 것입니다 ..!

나는 이것이 다른 방법으로 할 수 있다는 것을 알고 있지만 가능하다면 새로운 VS 2010 방식을 사용하여 이것을하고 싶습니다.


비슷한 정보를 찾고 있었지만 찾지 못했기 때문에 Visual Studio 2010 및 MSBuild 4.0과 함께 제공되는 .targets 파일을 살펴 보았습니다. 변환을 수행 할 MSBuild 작업을 찾을 수있는 가장 좋은 장소라고 생각했습니다.

내가 알 수있는 한, 다음 MSBuild 작업이 사용됩니다.

<Project ToolsVersion="4.0"
         DefaultTargets="Deploy"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <UsingTask TaskName="TransformXml"
               AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

    <PropertyGroup>
        <ProjectPath>C:\Path to Project\Here</ProjectPath>
        <DeployPath>C:\Path to Deploy\There</DeployPath>
        <TransformInputFile>$(ProjectPath)\Web.config</TransformInputFile>
        <TransformFile>$(ProjectPath)\Web.$(Configuration).config</TransformFile>
        <TransformOutputFile>$(DeployPath)\Web.config</TransformOutputFile>
        <StackTraceEnabled>False</StackTraceEnabled>
    </PropertyGroup>


    <Target Name="Transform">
        <TransformXml Source="$(TransformInputFile)"
                      Transform="$(TransformFile)"
                      Destination="$(TransformOutputFile)"
                      Condition="some condition here"
                      StackTrace="$(StackTraceEnabled)" />
    </Target>
</Project>

위의 내용을 테스트했으며 작동하는지 확인할 수 있습니다. 빌드 스크립트에 더 잘 맞도록 구조를 약간 조정해야 할 수도 있습니다.


패키지 대상을 사용하고 임시 디렉토리를 지정하여이를 수행 할 수 있어야합니다.

msbuild solution.sln /p:Configuration=Release;DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=..\publish

http://pattersonc.com/blog/index.php/2010/07/15/visual-studio-2010-publish-command-from-msbuild-command-line/


또는 XDT 변환 도구 를 사용해보십시오 .

http://ctt.codeplex.com

모호한 msbuild 대상을 엉망으로 만드는 대신 이것을 사용하고 있습니다. web.config 뿐만 아니라 app.config에서도 작동합니다 .


다음과 같은 변화로 나를 위해 일했습니다.

<MSBuild Projects="$(ProjectFile)"
         Targets="ResolveReferences;_WPPCopyWebApplication"
     Properties="WebProjectOutputDir=TempOutputFolder;OutDir=$(WebProjectOutputDir);Configuration=$(Configuration);" />

MsBuild 폴더 아래의 Microsoft.WebApplication.targets 파일에서

_CopyWebApplication

This target will copy the build outputs along with the 
content files into a _PublishedWebsites folder.

This Task is only necessary when $(OutDir) has been redirected
to a folder other than ~\bin such as is the case with Team Build.

The original _CopyWebApplication is now a Legacy, you can still use it by 
 setting $(UseWPP_CopyWebApplication) to true.
By default, it now change to use _WPPCopyWebApplication target in
 Microsoft.Web.Publish.targets.   
It allow to leverage the web.config trsnaformation.

저는 MSBuild에 대한 전문가는 아니지만이 링크의 정보를 사용하여 동일한 작업을 수행 할 수있었습니다.

http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx

기사 하단에 MSBuild와 관련된 섹션이 있습니다. 도움이 되었기를 바랍니다.


이 문제를 해결하기 전에 며칠 동안 검색 한 후이 주제에 대한 또 다른 답변 :

게시 프로필과 구성 이름이 일치해야합니다.

In my case mine didn't. Manually publishing through the publishing profile gave me the result I wanted, because my configuration was set in the publish profile. MSBuild however tries to be intelligent and magically connects the publish profile and configuration based on name. (Adding the /p:Configuration in the command resulted in other strange errors about the outputpath of a referenced project).

Just to be exactly clear in what I mean:

MSBuild statement from command line

msbuild myproject.csproj -t:Clean -t:Rebuild /p:DeployOnBuild=true /p:PublishProfile="Development"

WORKS

  • Publish Profile name: Development
  • Solution Configuration name: Development

DOES NOT WORK

  • Publish Profile name: Development
  • Solution Configuration name: Dev

Hope this helps!

참고URL : https://stackoverflow.com/questions/2905151/msbuild-script-and-vs2010-publish-apply-web-config-transform

반응형