15

我使用以下脚本将我的 ASP.NET MVC 应用程序部署到我们的 Web 服务器:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe MySolution.sln^
/p:Configuration=TeamCity-Test^
/p:OutputPath=bin^
/p:DeployOnBuild=True^
/p:DeployTarget=MSDeployPublish^
/p:MsDeployServiceUrl=https://mywebserver.com:8172/msdeploy.axd^
/p:username=MyDomain\MyUser^
/p:password=MyPassword^
/p:AllowUntrustedCertificate=True^
/p:DeployIisAppPath=mywebsitename.com^
/p:MSDeployPublishMethod=WMSVC

现在我需要指定不同步 /uploads 文件夹。我可以在这个脚本中指定吗?谢谢!

澄清:我的项目中有 Uploads 文件夹。我想让 Web Deploy 创建文件夹。我不希望它从我的 Web 服务器中删除文件夹/子文件夹/文件,因为它包含用户上传的内容。

澄清#2:我刚刚找到了这个SkipExtraFilesOnServer=True选项。但是,我不希望这是全球性的。我想将其设置为单个文件夹。

4

1 回答 1

21

UPDATE: Apparently, what you really want is prevent web deploy from removing existing directory on the destination server, but still have the folder created in case it's not there. You can accomplish this as follows:

  • create YourWebProjectName.wpp.targets file next to you the project file with the following content:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <ItemGroup>
          <MsDeploySkipRules Include="SkipELMAHFolderFiles">
          <SkipAction></SkipAction>
          <ObjectName>filePath</ObjectName>
          <AbsolutePath>$(_DestinationContentPath)\\NameOfYourFolder\\.*</AbsolutePath>
          <Apply>Destination</Apply>
          <XPath></XPath>
        </MsDeploySkipRules>
    
        <MsDeploySkipRules Include="SkipELMAHFolderChildFolders">
          <SkipAction></SkipAction>
          <ObjectName>dirPath</ObjectName>
          <AbsolutePath>$(_DestinationContentPath)\\NameOfYourFolder\\.*\\*</AbsolutePath>
          <Apply>Destination</Apply>
          <XPath></XPath>
        </MsDeploySkipRules>
      </ItemGroup>
    </Project>
    

Change NameOfYourFolder and YourWebProjectName accordingly. This assumes, you have it in the root, I believe, you can use relative path if it's not the case.

  • The first MsDeploySkipRules entry tells webdeploy not to remove any files in Name_OfYourFolder.
  • The second MsDeploySkipRules tells webdeploy not to remove any child folders in Name_OfYourFolder.

Also, to have the folder created if it's not present on the destination server, you have to do the following:

  • include the folder into the project
  • add a dummy DeployemntPlaceholder.txt file into it and include it into the project as well

DeployemntPlaceholder.txt is required to tell MSBUild to add the folder into the package: empty folders are ignored.

I've tested this approach and it works fine when you run publish in the manner you've shown. I've used this answer to get the msbuild items syntaxt right. I believe, this is a MSBuild way to customize flags, passed to webdeploy by MSBuild Deployment Pipeline.

If you ran MSDeploy directly, you could use skip arguments in the following manner:

-skip:objectname='filePath',absolutepath='logs\\.*\\someNameToExclude\.txt'

UPDATE 2

You might also want to have ACL write permissions set on your \Uploads folder - there's a complete guide to do this: Setting Folder Permissions On Web Publish

Conserning the original question "Specifying folders not to sync in Web Deploy", the easiest way to do this is as follows:

You can create a publish profile and add the following lines:

<PropertyGroup>
  <ExcludeFilesFromDeployment>
    File1.aspx;File2.aspx
  </ExcludeFilesFromDeployment>
  <ExcludeFoldersFromDeployment>
    Folder1;Folder2
  </ExcludeFoldersFromDeployment>
</PropertyGroup> 

I've tested this approach for excluding files using publish profiles. An easy guide is here (scroll to Edit the .pubxml file to exclude robots.txt section).

You can also do this in .wpp.targets file or edit you csproj. See more information at Web Deployment FAQ for Visual Studio and ASP.NET

于 2013-08-16T12:24:48.593 回答