Ignore Directory in MSDeploy and MSBuild

2019-08-10 18:54发布

问题:

I have a Web Site project that is deployed using "Publish Web Site" feature in Visual Studio. I understand this feature uses WebDeploy (MSDeploy) which calls MSBuild to compile the site.

There is a directory within the website that needs to be ignored by both WebDeploy and MSBuild because it breaks the site.

I was able to configure the deployment configuration file (.pubxml) to make WebDeploy ignore directory:

  <PropertyGroup>
    ...
    <ExcludeFoldersFromDeployment>node_modules</ExcludeFoldersFromDeployment>
  </PropertyGroup>

I was also able to get the site to compile by making the directory hidden in the file system.

However, I am unable to get MSBuild to ignore the directory when called from WebDeploy.

How do I ignore the directory anytime the site is compiled?

Update

The compiler logs this in the Output Window when it fails:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.WebSite.Publishing.targets(172,5): Error MSB4018: The "CollectFilesinFolder" task failed unexpectedly.

回答1:

You want to apply a skip rule so that the directory is ignored by the synchronisation process completely.

Add this to your .pubxml file:

<ItemGroup>
  <MsDeploySkipRules Include="SkipNodeModules">
    <AbsolutePath>node_modules</AbsolutePath>
  </MsDeploySkipRules>
</ItemGroup>

If you run into problems with it not working, you may be seeing this problem. If so, just add:

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