让MSDeploy在CCNet任务中跳过特定文件夹和文件类型

4
我希望MSDeploy在使用同步时可以跳过其他文件夹中特定的文件夹和文件类型。目前,我正在使用CCNet调用MSDeploy并使用同步动词将网站从构建服务器传输到暂存服务器。由于目标位置上有应用程序/用户上传的文件等,需要排除特定文件夹,以免被删除。此外,站点创建了清单文件,需要保留在目标位置。
目前,我使用-enableRule:DoNotDeleteRule,但这会在目标位置上留下旧文件。
<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>

我尝试使用跳过操作,但遇到了问题。最初,我删除了DoNotDeleteRule并替换为(多个)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>

但这会导致以下结果:


错误:源(iisApp)和目标(contentPath)对于给定的操作不兼容。
错误计数: 1.

所以我从iisApp改为contentPath,而不是使用dirPath、absolutePath,只用Directory,就像这样:
<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>

这个错误信息是:Illegal characters in path。

< buildresults>
信息: 正在添加 MSDeploy.contentPath (MSDeploy.contentPath)。
信息: 添加 contentPath (C:\WWWRoot\MySite
-skip:Directory=assets
-skip:Directory=survey
-skip:Directory=content/scorecardsupport
-skip:Directory=Desktop/docs
-skip:Directory=_TempImageFiles)。
信息: 添加 dirPath (C:\WWWRoot\MySite
-skip:Directory=assets
-skip:Directory=survey
-skip:Directory=content/scorecardsupport
-skip:Directory=Desktop/docs
-skip:Directory=_TempImageFiles)。
< /buildresults>

< buildresults>
错误: 路径中包含非法字符。
错误计数: 1。
< /buildresults>

所以我需要知道如何配置此任务,使得被引用的文件夹不会在同步时删除其内容,并且完成/自定义文件夹中的*.manifest和*.aspx文件也会被跳过。


将该程序移动到 NAnt 任务并使用 NAnt <exec>。如果需要,使用 NAntBuilder 进行调试。http://www.polestarsoft.com/products/nantbuilder/ - Adam Bruss
CCNet项目中有很多其他的内容...我能混合使用nant和ccnet吗?还是我必须将整个构建脚本转换为nant? - Simon Martin
您可以在<tasks>、<prebuild>或<publisher>块中放置任意数量的任务。例如:<tasks><exec>...</exec><nant>...</nant><exec>...</exec></tasks>。任务按照它们在文件中存在的顺序执行。我非常喜欢Nant的一个功能,就是它能够运行C#脚本。http://nant.sourceforge.net/release/0.91/help/tasks/script.html - Adam Bruss
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>

1

请看一下这篇MSDN文章:Web Deployment: Excluding Files and Folders via the Web Application's Project File。特别是“排除特定文件/文件夹”部分。这将阻止目录、文件和文件/目录模式匹配既包括在部署包中作为内容,也在部署时在目标位置被忽略。

然而,我会退后一步,问一下为什么这些文件首先存在于您的Web项目中。我在IIS上处理用户上传的内容的方式是添加一个虚拟目录到我的Web应用程序。虚拟目录的内容(以及vdir本身的配置)在进行Web部署包同步时都会被忽略。这也使您能够将客户端内容目录托管在任何您喜欢的地方,这具有许多优势(例如,更大的磁盘驱动器,防止不道德的用户尝试使用垃圾数据填充硬盘,等等)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接