Okay, I was able to add the NuGet package with this command: dotnet nuget add source --name domaindriverdev https://www.myget.org/F/domaindrivendev/api/v3/index.json
I removed ./bin and ./obj afterwards, then ran dotnet restore MyProject.csproj and dotnet build MyProject.csproj. The error described in this issue went away, however I'm facing a new one:
PS C:\Users\MyUserName\Projects\MyRepo\MyService> dotnet swagger tofile --output swagger.json .\bin\Debug\netcoreapp2.2\MyService.dll v1
Unhandled Exception: StructureMap.Building.StructureMapBuildException: Error while building type Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions. See the inner exception for details
1.) new ConfigureSwaggerGeneratorOptions(*Default of IOptions<SwaggerGenOptions>*, *Default of IServiceProvider*, *Default of IHostingEnvironment*)
2.) Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions
3.) Instance of IConfigureOptions<SwaggerGeneratorOptions> (Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions)
4.) All registered children for IEnumerable<IConfigureOptions<SwaggerGeneratorOptions>>
5.) Instance of IEnumerable<IConfigureOptions<SwaggerGeneratorOptions>>
6.) new OptionsFactory`1(*Default of IEnumerable<IConfigureOptions<SwaggerGeneratorOptions>>*, *Default of IEnumerable<IPostConfigureOptions<SwaggerGeneratorOptions>>*, *Default of IEnumerable<IValidateOptions<SwaggerGeneratorOptions>>*)
7.) OptionsFactory<SwaggerGeneratorOptions> ('48905920-c9cd-4ae8-ace8-eaeebb281f4f')
8.) Instance of IOptionsFactory<SwaggerGeneratorOptions> ('48905920-c9cd-4ae8-ace8-eaeebb281f4f')
9.) new OptionsManager`1(*Default of IOptionsFactory<SwaggerGeneratorOptions>*)
10.) OptionsManager<SwaggerGeneratorOptions> ('991c1d92-470e-4242-8e09-20152b229dd7')
11.) Instance of IOptions<SwaggerGeneratorOptions> ('991c1d92-470e-4242-8e09-20152b229dd7')
12.) Container.GetInstance(IOptions<SwaggerGeneratorOptions>)
13.) Lambda: Invoke(value(StructureMap.ContainerExtensions+<>c__DisplayClass9_0).descriptor.ImplementationFactory, IContext.GetInstance())
14.) Instance of Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions (System.Object)
15.) new SwaggerGenerator(*Default of SwaggerGeneratorOptions*, *Default of IApiDescriptionGroupCollectionProvider*, *Default of ISchemaGenerator*)
16.) Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator
17.) Instance of Swashbuckle.AspNetCore.Swagger.ISwaggerProvider (Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator)
18.) Container.GetInstance(Swashbuckle.AspNetCore.Swagger.ISwaggerProvider)
---> System.IO.FileNotFoundException: Could not find file 'C:\Users\MyUserName\Projects\MyRepo\MyService\bin\Debug\netcoreapp2.2\dotnet-swagger.xml'.
The file dotnet-swagger.xml does indeed not exist. My guess is that it should be MyService.xml instead?
Full disclosure: I'm a noob regarding dotnet tooling and C# development in general. So please forgive me when I'm doing any mistakes that should be obvious. 馃槄
[EDIT]
There is another issue regarding this: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1518, however it was closed due to no proper steps for reproduction. Well, here we are.
Most helpful comment
I've been battling with this issue myself. It appears to occur when you have dotnet 3.0 installed on your system, and you're trying to extract Open API specs out of a Startup Assembly that targets dotnet 2.*.
I assume when you invoke the swagger cli tool it's using dotnet 3.0 to host the tool, but then it has to load a dotnet 2.* startup assembly to extract the specs, and somewhere in this process it encounters assembly loading issues because of it.