I was able to solve this using just a custom MSBuild target in the publish profile .pubxml
file. Follow the steps below.
The end result is that this MSBuild target will copy all .xml
files from the Web API's bin folder to the bin folder where you are publishing. No need to copy these files to App_Data
.
1) Open the appropriate .pubxml
file from [Project Folder]\Properties\PublishProfiles
.
2) Add this snippet within the <Project><PropertyGroup>
tag:
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
3) Add this snippet after the <PropertyGroup>
tag:
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="bin\*.xml" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Credit goes to this answer which was addressing how to include files from outside the project directory when publishing.