因此,我已经安装了VS 2010,并且正在修改我的MSBuild脚本,以便进行TeamCity构建集成.除了一个例外,一切都很顺利.

我如何告诉MSBuild我想要应用我在发布构建时创建的Web.conifg转换文件……

我有以下生成编译后的网站,但它输出一个web.配置,网络.调试.配置和网络.释放将配置文件(全部3个)保存到已编译的输出目录中.在studio中,当我执行"发布到文件"系统时,它将进行转换,并且只输出Web.配置适当的更改...

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

任何帮助都会很好..!

I know this can be done by other means but I would like to do this using the new VS 2010 way if possible

推荐答案

我正在寻找类似的信息,但没有完全找到,所以我在Visual Studio2010和MSBuild4.0附带的.target文件中做了一些搜索.我认为这是查找将执行转换的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>

我已经测试了上面的内容,可以确认它工作正常.您可能需要稍微调整一下 struct ,以便更好地适应您的构建脚本.

Asp.net相关问答推荐

检测 ASP.NET 中的内存泄漏

jQuery隐藏字段

ASP.NET web api 无法获取 application/x-www-form-urlencoded HTTP POST

捕获对 ASP.NET ASMX Web 服务的 SOAP 请求

未知的网络方法.参数名称:methodName

使用 Owin 身份验证的服务器端声明缓存

如何判断 IIS 是处于 32 位还是 64 位模式

为什么我不能在 ASP.net MVC 中使用服务器控件?

ASP .NET Button 事件处理程序不会在第一次单击时触发,而是在 PostBack 后的第二次单击时触发

如何防止aspxerrorpath作为查询字符串传递给 ASP.NET 自定义错误页面

Cache.Add 绝对过期 - 是否基于 UTC?

VS 2010 中缺少 App_Code 文件夹

为什么 HttpWebRequest 会抛出异常而不是返回 HttpStatusCode.NotFound?

Twitter Bootstrap 和 ASP.NET GridView

使用 Twitter Bootstrap 在 @html.actionlink 中显示 html

HttpContext.Current属性的跨线程使用及相关的东西

如何遍历自定义 vb.net 对象的每个属性?

将 HTML 字符串转换为图像

Ashx 文件中的 HttpContext.Current.Session 为空

如何使 URL 重写与 web.Release.config 转换一起工作?