MSBuild - Determine a solution's _PublishedWebsites

前端 未结 1 1532
不思量自难忘°
不思量自难忘° 2020-12-17 04:28

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

I cur

相关标签:
1条回答
  • 2020-12-17 05:25

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

    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>
    

    The command line-variant is:

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

    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.

    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)Websites\MyCustomFolderName</WebProjectOutputDir>
        </PropertyGroup>
    </Project>
    

    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:\Development\WebOutputTest\
    
    0 讨论(0)
提交回复
热议问题