asp.net webapi publish - xml files not copy

asp.net Mvc-4asp.net Web-ApiMsbuildPublish Profiles

asp.net Mvc-4 Problem Overview


I have MVC 4.0 WebApi project with auto generated help based on this.

My model classes are stored it another projects in my solution. Generation of xml file is enabled for every project (Project Properties -> Build -> OutPut -> XML Documentation file - Enabled).

In local debug all is ok - xml files are copied to project directory and i see comments for fields / classes from another projects.

But when i use publish profile (to Folder), xml files don't copy to output folder. Only one xml file from main WebApi project is copied. So i don't see comments to classes from other projects.

asp.net Mvc-4 Solutions


Solution 1 - asp.net Mvc-4

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 - asp.net Mvc-4

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 - asp.net Mvc-4

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 - asp.net Mvc-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:

    CustomCollectFiles; $(CopyAllFilesToSingleFolderForPackageDependsOn);

    CustomCollectFiles; $(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.

Solution 5 - asp.net Mvc-4

Open your publishprofile (*.pubxml) and include this code into "Project" element:

<ItemGroup>
	<Content Include="bin\yourDocumentationFile.xml">
		<CopyToOutputDirectory>true</CopyToOutputDirectory>
	</Content>
    <!-- Include a content to each documentation file -->
</ItemGroup>

Solution 6 - asp.net Mvc-4

One way is to add the XML files to your "App_Data"folder inside the project, and then inside visual studio, select a file to its property "Copy to Ouput Directory" to "Always".enter image description here

Solution 7 - asp.net Mvc-4

Complementing the previous answer, there is also another type of tag to include, as the article below:

https://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files

Tag:

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

Solution 8 - asp.net Mvc-4

If your site is using a Publish Profile (for example if you downloaded one from your ISP) you need to make sure that the following option is set to False

<ExcludeApp_Data>False</ExcludeApp_Data>

The XML file's properties can be set to: Build Action - Content, Copy To Output Directory - Always

But if the parameter above is set to True in the Publish Profile then your XML file will never be published. Learned this the hard way.

Solution 9 - asp.net Mvc-4

you can change the existing condition:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' OR '$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>ProjectName.xml</DocumentationFile>
</PropertyGroup>

Solution 10 - asp.net Mvc-4

If you do not want the Documentation File go to the HelpPageConfig.cs and Comment Out

config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")))

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexander SubbotinView Question on Stackoverflow
Solution 1 - asp.net Mvc-4grimusView Answer on Stackoverflow
Solution 2 - asp.net Mvc-4Chandrika PrajapatiView Answer on Stackoverflow
Solution 3 - asp.net Mvc-4martinossView Answer on Stackoverflow
Solution 4 - asp.net Mvc-4KeithView Answer on Stackoverflow
Solution 5 - asp.net Mvc-4Leandro EscaldelaiView Answer on Stackoverflow
Solution 6 - asp.net Mvc-4Toan NguyenView Answer on Stackoverflow
Solution 7 - asp.net Mvc-4IvanView Answer on Stackoverflow
Solution 8 - asp.net Mvc-4ScottView Answer on Stackoverflow
Solution 9 - asp.net Mvc-4HamidRezaView Answer on Stackoverflow
Solution 10 - asp.net Mvc-4Ryan DooleyView Answer on Stackoverflow