asp.net webapi publish - xml files not copy
Asked Answered
S

10

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.

Sassafras answered 15/5, 2014 at 14:41 Comment(1)
S
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.

Stavanger answered 13/1, 2016 at 21:54 Comment(3)
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.Gerbil
And also click Show All Files make sure .xml files are Included In ProjectSixpack
I got as far as reading "I had only enabled..." before having my own Doh! moment for this. Thank you!Dowitcher
C
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

Codpiece answered 20/5, 2014 at 9:38 Comment(3)
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.Glauconite
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.Piles
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 vs2015Pigeon
C
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!

Congener answered 21/3, 2018 at 17:1 Comment(5)
I had to add this property and also perform the fix described in the answer @Stavanger provided to get it to work. Thanks for adding this answer!Rox
This fix did it for meVodka
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.Raptorial
THis includes all .xml of all assemblies. If you need to include only a few particular ones, use @Veats answer methodNonanonage
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)Flunky
V
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.

Veats answered 2/5, 2016 at 21:9 Comment(3)
Unfortunately this solution doesn't work for Web Deployment.Disrespectable
Sooo close. Credit to Ivan and his link to asp.net/mvc/overview/deployment/visual-studio-web-deployment/…. What you needed to do is also add a duplicate xml node of "CopyAllFilesToSingleFolderForPackageDependsOn" labelled "CopyAllFilesToSingleFolderForMsdeployDependsOn" This way MsDeploy will also work.Philbo
@Veats worked perfectly in WebApi2 (fx v4.7.2) in Visual Studio 2017, what a clean and fantastic solution! Thank you.Greengrocer
A
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>
Anything answered 2/8, 2017 at 15:44 Comment(0)
A
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

Accolade answered 16/5, 2014 at 0:6 Comment(4)
Do i undestand correctly that i should manualy copy xml file to Api project and repeat it after every comment/code changing?Sassafras
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.Accolade
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.Piles
This doesn't make any sense. The xml files are generated during the build process. They are not part of the project.Argol
F
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>
Flirt answered 10/10, 2016 at 21:48 Comment(0)
C
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.

Carnage answered 14/9, 2016 at 15:4 Comment(0)
I
0

you can change the existing condition:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' OR '$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>ProjectName.xml</DocumentationFile>
</PropertyGroup>
Illbehaved answered 23/5, 2021 at 4:34 Comment(0)
T
-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")))

Tacye answered 30/11, 2018 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.