My Technical Notes

Tuesday, 28 February 2017

Change Publish Profile to also publish `.xml` files found in bin directory

The Publish Profile file has a `.pubxml` extension. Publish Profiles are stored in the `Properties\PublishProfiles` folder.

To ensure that all XML files in the `bin` directory are also published, edit the `.pubxml` file to include the following `<Target/>` element before the `</Project>` end tag:


<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include=".\bin\*.xml" />
    <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
      <!--<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>-->
      <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>
<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>

  <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>

If you wished to exclude certain files, customise the filter `.bin\*.xml`to only include specific files.

No comments: