8

I am trying to find out how to exclude files when using the publishing feature in VS (2017 to be exact).

The documentation is not great, but it seems adding

<ItemGroup>
    <Content Update="file name">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

("file name" was set to web.config, but also folders and other files were tested)

to the profile.pubxml under <project> should do the trick, but it doesn't :(

I have tried changing "Never" to "false" as VS intelisense seems to suggest that.

I have also tried

<ItemGroup>
    <Content Update="file name" CopyToPublishDirectory="Never" />
  </ItemGroup>

As that was suggested in different posts when Googling.

Does anyone have the solution for this?

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mark Cassidy
    Commented Jan 10, 2018 at 17:45

4 Answers 4

6

You could also add a property group called ExcludeFilesFromDeployment to your profile.pubxml publishing profile. I have mine setup like this:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <ExcludeFilesFromDeployment>
        bin\Sitecore.*.dll;
    </ExcludeFilesFromDeployment>
  </PropertyGroup>
</Project>

To make sure non of the Sitecore binaries are deployed.

Also - in your VS Project you can just set the build action to none in the properties of the files. That will affect the project file, so it will apply to all publishing profiles, not just the one you are editing.

2
  • 1
    Be careful with this one, esp is you are referencingSitecore.Support.*.dll on your projects and expecting them to be deployed :)
    – jammykam
    Commented Jan 9, 2018 at 15:53
  • That works! Where have you found that element (ExcludeFilesFromDeployment)? I have not found that in any of the limited documentation I have read through ;) And it does not appear as an option in the intellisense. Commented Jan 10, 2018 at 8:47
6

Although this is off-topic, this is a common issue in Sitecore for those who are experimenting with Helix/Habitat. Anyway, you can also achieve this on the VS UI which essentially results to the project file snippet Anton has shown above. Just choose Properties on the file you want to not process and change the Build Action to None.

enter image description here

1
  • Not working my friend. Commented Nov 22, 2019 at 8:06
2

Try this one:

<ItemGroup>
  <None Update="file name" CopyToPublishDirectory="Never" />
</ItemGroup>

It will change build action from content to none and will exclude file from publishing.

2
  • I tried this as well, without any luck. Is it working for you? Commented Jan 9, 2018 at 19:06
  • 1
    You have to do this in the csproj file.
    – Richard Seal
    Commented Jan 10, 2018 at 13:13
0

In Visual Studio 2022 I have successfully used this settings:

  1. Go and edit the
    [ProjectName] \ Properties \ PublishProfiles \ FolderProfile.pubxml file in solution explorer.

  2. Add these lines inside PropertyGroup element:

     <ItemGroup>
         <Content Remove="Data\*.json" />
         <None Include="Data\*.json" />
     </ItemGroup>
    
  3. Then save the .pubxml file and try to publish the project.

"Content Remove" will remove the file from the content to deploy. "None Include" will keep the file in the solution explorer.

It's possible to set it up in the solution explorer for single files as well: right click the file in the solution explorer -> Properties and change the Build Action to None.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.