本文介绍了MSBuild - 确定解决方案的 _PublishedWebsites的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Web 开发目标文件,并希望以编程方式确定出现在_PublishedWebsites"下方的目录名称.

I am writing a web development targets file and would like to programmatically determine the name of the directory that appears beneath "_PublishedWebsites".

我目前必须使用这个:

$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites MyWebApplication

$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites MyWebApplication

有什么想法吗?

(我不会将此用于发布多个网站的解决方案)

(I am not using this for solutions with more than one website to publish)

推荐答案

.NET 4.0 中新的 Web Publishing Pipeline (WPP) 具有控制输出位置的方法.

The new Web Publishing Pipeline (WPP) in .NET 4.0 has a method for controlling the output location.

首先,您需要在执行 CopyWebApplication 目标期间选择加入 WPP.在命令行或 MSBuild 项目文件中设置以下 MSBuild 属性:

First, you need to opt-in to WPP during the execution of the CopyWebApplication target. Set the following MSBuild properties, either at command line or in the MSBuild project file:

<PropertyGroup>
    <UseWPP_CopyWebApplication>True</UseWPP_CopyWebApplication>
    <PipelineDependsOnBuild>False</PipelineDependsOnBuild>
</PropertyGroup>

命令行变体是:

/p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False

接下来,在与您的项目相同的目录中创建一个新的 MSBuild 目标文件,并将其命名为ProjectName.wpp.targets",其中ProjectName"是您的项目的文件名,减去扩展名.换句话说,如果您有MyWebsite.csproj",则需要创建MyWebsite.wpp.targets".我发现将目标文件添加到项目中也很有帮助.这不是必需的,但它使编辑更容易.

Next, create a new MSBuild targets file in the same directory as your project and name it "ProjectName.wpp.targets" where "ProjectName" is the filename of your project, minus the extension. In other words, if you have "MyWebsite.csproj" you need to create "MyWebsite.wpp.targets". I find it helps to add the targets file to the project as well. It's not required, but it makes it easier to edit.

在新的目标文件中,您需要覆盖 WebProjectOutputDir 属性.只有在调用 CopyWebApplication 时才这样做——换句话说,当OutDir"被重定向离开OutputPath"时:

In the new targets file, you will need to override the WebProjectOutputDir property. Only do this when CopyWebApplication will be called - in other words, when the "OutDir" is redirected away from the "OutputPath":

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <WebProjectOutputDir Condition="'$(OutDir)' != '$(OutputPath)'">$(OutDir)WebsitesMyCustomFolderName</WebProjectOutputDir>
    </PropertyGroup>
</Project>

就是这样 - 你应该很高兴.您可以通过设置 OutDir 属性在本地对其进行测试.不要忘记结尾的反斜杠:

That's it - you should be good to go. You can test it locally by setting the OutDir property. Don't forget the trailing backslash:

msbuild MyWebsite.csproj /p:OutDir=C:DevelopmentWebOutputTest

这篇关于MSBuild - 确定解决方案的 _PublishedWebsites的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:09