我有一个 Web 应用程序项目:
如您所见,有 3 个 robots.txt 文件 - 每个环境一个。还有 3 个发布配置文件。
现在,对于每个 pubxml,我想选择正确的“robots.xxx.txt”文件并将其重命名为“robots.txt”。理想情况下,我想利用 MSBuild 并将配置保留在每个 pubxml 文件中。
3 个发布配置文件中的每一个都使用 <WebPublishMethod>MSDeploy</WebPublishMethod>
.
编辑:
刚试过Richard Szalay answer ,然而无济于事。所有 3 个文件仍被复制到输出目录。这就是我的发布配置文件现在的样子
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>True</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\Temp\myproject</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
<ItemGroup>
<MsDeployReplaceRules Include="robots">
<ObjectName>filePath</ObjectName>
<Match>robots\.debug\.txt</Match>
<Replace>robots.txt</Replace>
</MsDeployReplaceRules>
</ItemGroup>
</Project>
最佳答案
您需要的是替换规则。只需将以下内容添加到您的发布配置文件中:
<ItemGroup>
<MsDeployReplaceRules Include="robots">
<ObjectName>filePath</ObjectName>
<Match>robots\.debug\.txt</Match>
<Replace>robots.txt</Replace>
</MsDeployReplaceRules>
</ItemGroup>
如果文件命名约定与您的发布配置文件匹配,您也可以创建一个
Robots.wpp.targets
文件在您的 Web 应用程序的根目录中,并使用以下内容:<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MsDeployReplaceRules Include="robots">
<ObjectName>filePath</ObjectName>
<Match>robots\.$(PublishProfileName)\.txt</Match>
<Replace>robots.txt</Replace>
</MsDeployReplaceRules>
</ItemGroup>
</Project>
关于msbuild - 如何重命名网络部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168484/