4

I want MSDeploy to skip specific folders and file types within other folders when using sync. Currently I'm using CCNet to call MSDeploy with the sync verb to take websites from a build to a staging server. Because there are files on the destination that are created by the application / user uploaded files etc, I need to exclude specific folders from being deleted on the destination. Also there are manifest files created by the site that need to remain on the destination.

At the moment I've used -enableRule:DoNotDeleteRule but that leaves stale files on the destination.

<exec>
    <executable>$(MsDeploy)</executable>
    <baseDirectory>$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\</baseDirectory>
    <buildArgs>-verb:sync 
        -source:iisApp="$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\" 
        -dest:iisApp="$(website)/$(websiteFolder)"
        -enableRule:DoNotDeleteRule</buildArgs>
    <buildTimeoutSeconds>600</buildTimeoutSeconds>
    <successExitCodes>0,1,2</successExitCodes>
</exec>

I have tried to use the skip operation but run into problems. Initially I dropped the DoNotDeleteRule and replaced it with (multiple) skip

<exec>
    <executable>$(MsDeploy)</executable
    <baseDirectory>$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\</baseDirectory>
    <buildArgs>-verb:sync 
        -source:iisApp="$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\" 
        -dest:iisApp="$(website)/$(websiteFolder)"
        -skip:objectName=dirPath,absolutePath="assets" 
        -skip:objectName=dirPath,absolutePath="survey" 
        -skip:objectName=dirPath,absolutePath="completion/custom/complete*.aspx" 
        -skip:objectName=dirPath,absolutePath="completion/custom/surveylist*.manifest" 
        -skip:objectName=dirPath,absolutePath="content/scorecardsupport" 
        -skip:objectName=dirPath,absolutePath="Desktop/docs" 
        -skip:objectName=dirPath,absolutePath="_TempImageFiles"</buildArgs>         
    <buildTimeoutSeconds>600</buildTimeoutSeconds>
    <successExitCodes>0,1,2</successExitCodes>
</exec>

But this results in the following:


Error: Source (iisApp) and destination (contentPath) are not compatible for the given operation.
Error count: 1.

So I changed from iisApp to contentPath and instead of dirPath,absolutePath just Directory like this:

<exec>
    <executable>$(MsDeploy)</executable
    <baseDirectory>$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\</baseDirectory>
    <buildArgs>-verb:sync 
        -source:contentPath="$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\" 
        -dest:contentPath="$(website)/$(websiteFolder)"
        -skip:Directory="assets" 
        -skip:Directory="survey" 
        -skip:Directory="content/scorecardsupport" 
        -skip:Directory="Desktop/docs" 
        -skip:Directory="_TempImageFiles"</buildArgs>           
    <buildTimeoutSeconds>600</buildTimeoutSeconds>
    <successExitCodes>0,1,2</successExitCodes>
</exec>

and this gives me an error: Illegal characters in path:

< buildresults>
Info: Adding MSDeploy.contentPath (MSDeploy.contentPath).
Info: Adding contentPath (C:\WWWRoot\MySite
-skip:Directory=assets
-skip:Directory=survey
-skip:Directory=content/scorecardsupport
-skip:Directory=Desktop/docs
-skip:Directory=_TempImageFiles).
Info: Adding dirPath (C:\WWWRoot\MySite
-skip:Directory=assets
-skip:Directory=survey
-skip:Directory=content/scorecardsupport
-skip:Directory=Desktop/docs
-skip:Directory=_TempImageFiles).
< /buildresults>

< buildresults>
Error: Illegal characters in path.
Error count: 1.
< /buildresults>

So I need to know how to configure this task so the folders referenced do not have their contents deleted in a sync and that that *.manifest and *.aspx files in the completion/custom folders are also skipped.

4

2 回答 2

5

这个问题是......换行符!我将每个 -skip 指令拆分为导致路径中的非法字符的新行。内联运行所有跳过指令已经解决了这个问题:

<exec>
  <executable>$(MsDeploy)</executable>
  <baseDirectory>$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\</baseDirectory>
  <buildArgs>-verb:sync 
            -source:contentPath="$(ProjectsDirectory)$(projectName)$(ProjectsWorkingDirectory)\Website\" 
            -dest:contentPath="C:\WWWRoot\$(websiteFolder)" -skip:Directory="assets" -skip:Directory="_TempImageFiles" -skip:objectName=dirPath,absolutePath="\\Desktop\\Docs"
  </buildArgs>          
  <buildTimeoutSeconds>600</buildTimeoutSeconds>
  <successExitCodes>0,1,2</successExitCodes>
</exec>
于 2012-06-26T13:57:38.797 回答
1

请查看这篇题为Web 部署:通过 Web 应用程序的项目文件排除文件和文件夹的MSDN 文章。特别是“排除特定文件/文件夹”部分。这将阻止目录、文件和文件/目录模式匹配作为内容包含在部署包中,以及在部署时在目标上被忽略。

但是,我会退后一步,首先询问为什么这些文件存在于您的 Web 项目中。我在 IIS 上处理用户上传内容的方式是向我的 Web 应用程序添加一个虚拟目录。在 web 部署包上进行同步时,将忽略虚拟目录的内容(以及 vdir 本身的配置)。这也为您提供了将客户端内容目录托管在您喜欢的任何地方的好处,这有很多优势(即更大的磁盘驱动器,防止试图用垃圾数据填充硬盘的不道德用户的拒绝服务等)

于 2012-06-24T03:10:13.403 回答