Build/Test Issues

Microsoft.AspNetCore.Mvc.Testing and finding documentation

Started by Argamon on 2,167 views

I want to write some integration tests for an AspNetCore web api.

In the startup code (Program.cs) there is some code setting up swagger with documentation.

builder.Services
      .AddSwaggerGen(option =>  option.IncludeXmlComments(filePath));

So how to get this filePath?

If you look up in the net you find something like this:
var filePath = Path.Combine(AppContext.BaseDirectory, CommentFile);


As long time NCrunch user I am used to rewrite code like this to get the assembly of a type in the project and look for the xml file in the assembly´s directory.

Sadly this does not work here as the NuGet package Microsoft.AspNetCore.Mvc.Testing has a targets file which makes NCrunch copy the assembly (but not the documentation file) to the directory.

So building the solution leads to an output like this:

bin
  Debug
    api.dll
    api.xml
    api.test.dll


NCrunch creates a structure like this:

1234
   1
      bin
        Debug
          api.dll
          api.xml
   2
      bin
        Debug
          api.test.dll



Once I add the NuGet package Micrsoft.AspNetCore.Mvc.Testing to my test project the result changes to:

1234
   1
      bin
        Debug
          api.dll
          api.xml
   2
      bin
        Debug
          api.dll
          api.test.dll


Of course now all my tests fail, cause the file api.xml is not found.

Is there any solution to this?
Omg, I am sorry for opening this up here in the forums.

After trying to figure out how this works and why everything but the xml file is copied now for hours, I found out that a few levels higher in the repo someone had placed a Directory.build.props with AllowedReferenceRelatedFileExtensions, which effectively blocked copying the xml file.

By adding my own version of the Directory.build.props also including .xml everything works as a charm ;)
This post has been deleted.

Post a reply

Log in to reply.