asp.net webapi publish - xml files not copy

Solution 1:

I had a similar issue, for the me the answer was a bit of a "doh!" moment.

In the project settings, I had only enabled the XML documentation file under the Debug configuration, and not under Release. I was deploying with Release, and so the XML documentation was not actually getting generated. So the fix was making sure to enable the XML documentation for both Debug and Release configurations.

Solution 2:

You can do it by two different way :

1) Go to your project property --> select build option --> check "XML documentation File" --> add path "App_data\XMLDocument.xml" --> save setting, build your project --> include your XMLDocument.xml file --> select property --> copy to output directory --> select "Copy always"

2) Go to your project property --> select "Package/Publish Web" option --> items to displays --> select "all files in this project" from dropdown

Solution 3:

I had the same problem, that only the xml file from the webapi project has been deployed.

To fix it, I had to add this to my Web(Api) project file, within the first PropertyGroup element.

<ExcludeXmlAssemblyFiles>false</ExcludeXmlAssemblyFiles>

After that, the documentation xml-files of all projects (where it's enabled) has been published!

Solution 4:

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.