Wpp.targets中的MsDeploySkipRules不使用PublishProfiles

时间:2013-08-14 07:52:23

标签: asp.net visual-studio-2012 msbuild publish-profiles

我通过visual studio通过PublishProfile发布我的MVC项目(通过UI,右键单击项目,发布)并勾选清除目标文件夹的选项。 但我不希望清除特定文件夹“下载”

我花了无数个小时试图完成这项工作,我想我的代码与解释here的人完全相同,但它仍会删除下载文件夹

另外作为下面的示例,我有“favicon”的ExcludeFromPackageFiles,如果我取消选择目标文件夹的删除(只是为了表明我的wpp目标实际上正在运行)。

下面是我的projectname.wpp.targets文件

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- this doesnt work -->
  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
  </PropertyGroup>

  <PropertyGroup>
    <UseMsDeployExe>true</UseMsDeployExe>
  </PropertyGroup>

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipErrorLogFolder1">
        <SkipAction>Delete</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>ErrorLog</AbsolutePath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

  <!-- this works! -->
  <ItemGroup>
    <ExcludeFromPackageFiles Include="favicon.ico">
      <FromTarget>ContactManager.Mvc.wpp.targets</FromTarget>
    </ExcludeFromPackageFiles>
  </ItemGroup>

</Project>

任何想法?

1 个答案:

答案 0 :(得分:5)

(1)示例中的AbsolutePath值是从我的跳过规则示例中复制/粘贴的。您需要将该值更改为Downloads文件夹的路径。

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipDownloadsFolder">
        <SkipAction>Delete</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>Downloads</AbsolutePath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

(2)从Visual Studio中发布时,无法使用自定义跳过规则。您必须从命令提示符使用MSBuild发布。 my question的本质是将VS中管理的发布配置文件的便利性与自定义跳过规则(需要命令行)的实用程序相结合,因为从VS 2012 Update 3开始,命令的限制线还没有解除。

我的MSBuild命令如下所示:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"

如果我尝试在VS 2012中发布,我会收到以下错误,即使“-verb:sync”在输出中清晰可见:

2>Start Web Deploy Publish the Application/package to http://my.website.example.com/MSDEPLOYAGENTSERVICE ...
2>C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe 
  -source:manifest='C:\inetpub\wwwroot\My.Website\obj\Release\Package\My.Website.SourceManifest.xml' 
  -dest:auto,ComputerName='http://my.website.example.com/MSDEPLOYAGENTSERVICE',UserName='...',Password="...",IncludeAcls='False',AuthType='NTLM' 
  -verb:sync 
  -disableLink:AppPoolExtension 
  -disableLink:ContentExtension 
  -disableLink:CertificateExtension 
  -skip:skipaction='Delete',objectname='filePath',absolutepath='ErrorLog' 
  -skip:objectname='dirPath',absolutepath='obj\\Release\\Package\\PackageTmp\\App_Data$' 
  -skip:objectname='dirPath',absolutepath='MyWebsite/\\App_Data$' 
  -setParamFile:"C:\inetpub\wwwroot\My.Website\obj\Release\Package\My.Website.Publish.Parameters.xml" 
  -retryAttempts=2 
2>MSDEPLOY(0,0): Error : The verb must be specified by using the -verb argument.
2>MSDEPLOY(0,0): Error count: 1.