87

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.

Alexander Subbotin
  • 911
  • 1
  • 7
  • 5
  • [API help not show Body Parameters descriptions. In class properties missing description info. Just add DescriptionAttribute to property](https://stackoverflow.com/questions/50844202/vs-2017-webapi-help-page-no-document-provided/56688186#56688186) – Emil Nachev Jun 20 '19 at 14:37

10 Answers10

219

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.

grimus
  • 3,175
  • 2
  • 18
  • 26
  • 4
    Nice answer, but even with this option enabled for Release, the file is present in the bin/Release folder, but Publish does not copy the file. – MeanGreen Jun 08 '17 at 10:11
  • 2
    And also click `Show All Files` make sure .xml files are `Included In Project` – Timeless Jul 14 '17 at 01:57
  • 1
    I got as far as reading "I had only enabled..." before having my own Doh! moment for this. Thank you! – CT14.IT Aug 20 '21 at 09:17
46

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

Chandrika Prajapati
  • 867
  • 1
  • 6
  • 11
  • Clarification: if you do point 1) in both projects then in the main API project under the /bin/App_Data folder you will have both xml docs copied. – Juri Jun 18 '15 at 14:12
  • 5
    You really don't want to use "copy always". Just set them to type "Content". If you set "copy always", you will end up with an additional copy off App_Data under the bin directory. – TechSavvySam Jan 07 '16 at 16:05
  • 5
    Second method is not available for me.can't copy the xml_documentation file to the `bin` folder. the xmldocument is generated by other class library project. not the web project which I published.BTW in vs2015 – huoxudong125 Feb 29 '16 at 08:00
35

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!

martinoss
  • 5,268
  • 2
  • 45
  • 53
  • I had to add this property and also perform the fix described in the answer @grimus provided to get it to work. Thanks for adding this answer! – drewmerk Aug 15 '18 at 17:00
  • This fix did it for me – sebastian.roibu Oct 28 '19 at 14:40
  • 2
    Damn, that's why I love SO. Answer posted almost 4 years later after question was asked which totally solve my problem. Thank you, sir! It works :) The documentation for this property is basically non-existent. I couldn't find anything online. You basically have to look into `$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets` to see what's going on. – Mariusz Pawelski Mar 16 '20 at 15:34
  • 1
    THis includes all .xml of all assemblies. If you need to include only a few particular ones, use @Keith answer method – JotaBe Aug 31 '20 at 16:24
  • martinoss you say add it in the first `PropertyGroup` element but that would only have enabled it for Debug in my particular file. Need to check what the `PropertyGroup` elements are and add it where you need it (perhaps in two places, Debug and Release) – Reg Edit Jul 12 '21 at 18:35
30

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.

Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50
Keith
  • 20,636
  • 11
  • 84
  • 125
  • 1
    Unfortunately this solution doesn't work for Web Deployment. – Alexander Pavlenko Aug 23 '16 at 15:04
  • 6
    Sooo close. Credit to Ivan and his link to https://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files. What you needed to do is also add a duplicate xml node of "CopyAllFilesToSingleFolderForPackageDependsOn" labelled "CopyAllFilesToSingleFolderForMsdeployDependsOn" This way MsDeploy will also work. – cdmdotnet Nov 28 '16 at 19:31
  • 1
    @Keith worked perfectly in WebApi2 (fx v4.7.2) in Visual Studio 2017, what a clean and fantastic solution! Thank you. – timmi4sa Apr 10 '23 at 21:45
9

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>
8

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

Toan Nguyen
  • 11,263
  • 5
  • 43
  • 59
  • 1
    Do i undestand correctly that i should manualy copy xml file to Api project and repeat it after every comment/code changing? – Alexander Subbotin May 16 '14 at 14:02
  • 2
    No, in visual studio, right click on the app_data folder, and then choose add existing items. Next, select the output XML files to add them to the project. Finally, set the copy to Output Directory to always. – Toan Nguyen May 16 '14 at 20:26
  • 3
    You really don't want to use "copy always". Just set them to type "Content". If you set "copy always", you will end up with an additional copy off App_Data under the bin directory. – TechSavvySam Jan 07 '16 at 16:06
  • 5
    This doesn't make any sense. The xml files are generated during the build process. They are not part of the project. – ewahner Aug 25 '16 at 15:43
6

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>
Ivan
  • 61
  • 1
  • 1
0

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.

Scott
  • 143
  • 1
  • 9
0

you can change the existing condition:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' OR '$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>ProjectName.xml</DocumentationFile>
</PropertyGroup>
HamidReza
  • 1,726
  • 20
  • 15
-1

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")))

Ryan Dooley
  • 224
  • 1
  • 3
  • 16