Preferiría no utilizar toda una solución de proyecto de aplicación web sacada de la caja. Mi solución es utilizar la tarea XmlTransform definida en Microsoft.Web.Publishing.Tasks.dll directamente (esta tarea es el núcleo de WebConfigTransformation) De esta manera es lo suficientemente flexible y hace exactamente lo que espera que haga. Por ejemplo, aquí está el WebSiteTransformator.csproj que estoy usando para transformar web.config.
Aquí también hay un ejemplo de flexibilidad que es imposible de alcanzar con la original WebConfigTransformation: lleva a web.Template.config, aplica web. $ (Configuration) .config sobre él y escribe web.config. Esto nos permite agregar web.config en la lista de ignorar en control de fuente. Todavía es válida csproj ser referenciados por la página web:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>$(TEMP)\TransformWebConfig\bin</OutputPath>
<BaseIntermediateOutputPath>$(TEMP)\TransformWebConfig\obj\</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
<WebFolderName>$(SolutionDir)\MyWebSite\</WebFolderName>
</PropertyGroup>
<ItemGroup>
<Compile Include="Dummy.cs" />
</ItemGroup>
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BeforeBuild">
<TransformXml Source="$(WebFolderName)Web.Template.config"
Transform="$(WebFolderName)Web.$(Configuration).config"
Destination="$(WebFolderName)Web.config" />
</Target>
</Project>
Eso es un buen truco, pero dudo que lo implemente ... ¡gracias de cualquier manera! –
Sí, es una lástima que tenga que recurrir a un enfoque tan hacky para integrar msbuild, o incluso usar esa característica de transformación web.config, con proyectos de sitios web. Estoy evitando proyectos de sitios web y voy a utilizar proyectos de aplicaciones web tanto como pueda en el futuro. – porusan
Lo mismo aquí ....... –