MSBuild Script y VS2010 publish apply Web.transformación de Configuración


Por lo tanto, tengo VS 2010 instalado y estoy en el proceso de modificar mi script de MSBuild para nuestra integración de compilación de TeamCity. Todo está funcionando muy bien con una excepción.

¿Cómo puedo decirle a MSBuild que quiero aplicar la Web?conifg transformar archivos que he creado cuando publico la compilación...

Tengo lo siguiente que produce el sitio web compilado pero, produce una Web.config, Web.Depurar.config y Web.Lanzar.archivos de configuración (Los 3) en el directorio de salida compilado. En studio cuando realizo una publicación en el sistema de archivos que hará la transformación y solo la salida de la Web.config con los cambios apropiados...

<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>

Cualquier ayuda sería genial..!

Sé que esto se puede hacer por otros medios, pero me gustaría hacerlo usando la nueva forma VS 2010 si es posible

Author: abatishchev, 2010-05-25

6 answers

Estaba buscando información similar y no la encontré del todo, así que investigué un poco en el .se dirige a los archivos que vienen con Visual Studio 2010 y MSBuild 4.0. Pensé que era el mejor lugar para buscar la tarea de MSBuild que realizaría la transformación.

Por lo que he podido decir, se usa la siguiente tarea de 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>

He probado lo anterior y puedo confirmar que funciona. Es posible que tenga que ajustar la estructura un poco para que se ajuste a su construcción guión mejor.

 63
Author: Umar Farooq Khawaja,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-06-04 01:29:56

Debería ser capaz de lograr esto usando el destino del paquete y especificando el directorio temp.

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/

 13
Author: pattersonc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-07-15 19:47:31

Alternativamente, intente usar la Herramienta de transformación XDT :

Http://ctt.codeplex.com

Estoy usando esto en lugar de jugar con objetivos oscuros de msbuild. Funciona con app.config no solo web.config .

 8
Author: Brian Chavez,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-23 08:33:47

Funcionó para mí con el siguiente cambio

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

De Microsoft.Aplicación WEB.archivos de destino en la carpeta MSBuild

_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.
 5
Author: Syam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-24 03:43:08

Esta es una excelente valoración crítica sobre las transformaciones personalizadas:

Http://www.diaryofaninja.com/blog/2011/09/14/using-custom-webconfig-transformations-in-msbuild

Necesitábamos personalizar las implementaciones web un poco más de lo normal debido a toneladas de ASP clásico y otras maldades que tuvimos que acomodar. Este artículo ahorró horas de cavar a través de los objetivos de MS.

 1
Author: kenchilada,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-14 20:06:52

No soy experto en MSBuild, pero pude usar la información de este enlace para realizar la misma tarea:

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

Hay una sección relacionada con MSBuild cerca de la parte inferior del artículo. Espero que esto ayude.

 0
Author: Jonathan S.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-25 13:43:43