Question

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.

Était-ce utile?

La solution

The issue with this was... line breaks! Where I'd split each -skip directive to a new line that was causing the illegal characters in path. Running all the skip directives inline has solved this:

<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>

Autres conseils

Take a look at this MSDN article entitled Web Deployment: Excluding Files and Folders via the Web Application’s Project File. Specifically the section "Excluding Specific Files / Folders". This will stop directories, files, and file/dir pattern matches from both being included as content in the deployment package as well as ignored on the destination when deployed.

However, I would take a step back and ask why do these files exist in your web project in the first place. The way I've handled user uploaded content on IIS is by adding a virtual directory to my web application. The contents of virtual directories (and the provisioning of the vdir itself) is ignored when doing a sync on a web deploy package. This also gives you the benefit of hosting the client content directory anywhere you like which has a whole score of advantages (i.e. bigger disk drive, prevention of denial of service by unscrupulous users who try to fill your hard disk with garbage data, etc.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top