Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added package for using Cli tools from MsBuild like a NSwag.MSBuild #2685

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -1620,6 +1620,27 @@ public class SwaggerHostFactory
}
}
```
## Swashbuckle.AspNetCore.Cli.MsBuild ##

You can also use cli tools in MsBuild target. Just install it in your asp.net project as nuget package
and add new target section:

```xml

<Target Name="SwaggerJson" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Develop"
Command="$(SwashbuckleSwaggerCliExe_Net60) tofile --output swagger.json $(ProjectDir)/bin/$(Configuration)/net6.0/$(AssemblyName).dll documentName"/>
</Target>
```

Available props:
* SwashbuckleSwaggerCliExe_Core21
* SwashbuckleSwaggerCliExe_Core31
* SwashbuckleSwaggerCliExe_Net50
* SwashbuckleSwaggerCliExe_Net60
* SwashbuckleSwaggerCliExe_Net70

The idea of a package the same as in https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild

## Swashbuckle.AspNetCore.ReDoc ##

Expand Down
15 changes: 15 additions & 0 deletions Swashbuckle.AspNetCore.sln
Expand Up @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Swashbuckle.AspNetCore.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalApp", "test\WebSites\MinimalApp\MinimalApp.csproj", "{3D0126CB-5439-483C-B2D5-4B4BE111D15C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Swashbuckle.AspNetCore.Cli.MsBuild", "src\Swashbuckle.AspNetCore.Cli.MsBuild\Swashbuckle.AspNetCore.Cli.MsBuild.csproj", "{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -486,6 +488,18 @@ Global
{3D0126CB-5439-483C-B2D5-4B4BE111D15C}.Release|x64.Build.0 = Release|Any CPU
{3D0126CB-5439-483C-B2D5-4B4BE111D15C}.Release|x86.ActiveCfg = Release|Any CPU
{3D0126CB-5439-483C-B2D5-4B4BE111D15C}.Release|x86.Build.0 = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|x64.ActiveCfg = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|x64.Build.0 = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|x86.ActiveCfg = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Debug|x86.Build.0 = Debug|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|Any CPU.Build.0 = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|x64.ActiveCfg = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|x64.Build.0 = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|x86.ActiveCfg = Release|Any CPU
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -524,6 +538,7 @@ Global
{76692D68-C38C-4A7D-B3DA-DA78A393E266} = {0ADCB223-F375-45AB-8BC4-834EC9C69554}
{66590FBA-5FDD-4AC9-AF91-26ADAB33CCB8} = {0ADCB223-F375-45AB-8BC4-834EC9C69554}
{3D0126CB-5439-483C-B2D5-4B4BE111D15C} = {DB3F57FC-1472-4F03-B551-43394DA3C5EB}
{E36FBFDE-8279-4611-BFF3-8E90C9B9E276} = {15A55F4A-FC33-4D96-BAAD-FBDCDD96D5F5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36FC6A67-247D-4149-8EDD-79FFD1A75F51}
Expand Down
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Swashbuckle (Swagger) Command Line Tools for using on build.</Description>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);PopulateNuspec</GenerateNuspecDependsOn>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeContentInPack>false</IncludeContentInPack>
<IncludeSource>false</IncludeSource>
<IncludeSymbols>false</IncludeSymbols>
<MicrosoftExtensionsApiDescriptionServerPackageVersion>6.0.5</MicrosoftExtensionsApiDescriptionServerPackageVersion>
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
<PackageId>Swashbuckle.AspNetCore.Cli.MsBuild</PackageId>
<PackageTags>swagger;documentation;discovery;help;webapi;aspnet;aspnetcore;msbuild</PackageTags>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Swashbuckle.AspNetCore.Cli\Swashbuckle.AspNetCore.Cli.csproj" />
</ItemGroup>

<Target Name="PopulateNuspec">
<PropertyGroup>
<NuspecProperties>
authors=$(Authors);
configuration=$(Configuration);
description=$(PackageDescription);
id=$(PackageId);
licenseExpression=$(PackageLicenseExpression);
licenseUrl=$(LicenseUrl);
microsoftExtensionsApiDescriptionServerPackageVersion=$(MicrosoftExtensionsApiDescriptionServerPackageVersion);
projectUrl=$(PackageProjectUrl);
repositoryType=$(RepositoryType);
repositoryUrl=$(RepositoryUrl);
tags=$(PackageTags.Replace(';', ' '));
targetPath=$(TargetPath);
version=$(PackageVersion);
</NuspecProperties>
</PropertyGroup>
</Target>

</Project>
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
<owners>$authors$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">$licenseExpression$</license>
<licenseUrl>$licenseUrl$</licenseUrl>
<projectUrl>$projectUrl$</projectUrl>
<description>$description$</description>
<tags>$tags$</tags>
<repository type="$repositoryType$" url="$repositoryUrl$" />
<dependencies>
<group targetFramework=".NETStandard2.1">
<dependency id="Swashbuckle.AspNetCore" version="$version$" exclude="Build,Analyzers" />
</group>
</dependencies>
<developmentDependency>true</developmentDependency>
<references />
</metadata>
<files>
<file src="Swashbuckle.AspNetCore.Cli.MsBuild.props" target="build" />
<file src="Swashbuckle.AspNetCore.Cli.MsBuild.props" target="buildCrossTargeting" />
<file src="Swashbuckle.AspNetCore.Cli.MsBuild.props" target="buildTransitive" />

<file src="bin\Release\netcoreapp2.1\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/NetCore21" />
<file src="bin\Release\netcoreapp3.0\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/NetCore30" />
<file src="bin\Release\netcoreapp3.1\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/NetCore31" />
<file src="bin\Release\net5.0\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/Net50" />
<file src="bin\Release\net6.0\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/Net60" />
<file src="bin\Release\net7.0\**" exclude="**\Swashbuckle.AspNetCore.Cli.MsBuild.*" target="tools/Net70" />
</files>
</package>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OpenApiGenerateDocumentsOnBuild Condition=" '$(OpenApiGenerateDocumentsOnBuild)' == '' ">false</OpenApiGenerateDocumentsOnBuild>

<SwashbuckleSwaggerCliExe_Core21>dotnet "$(MSBuildThisFileDirectory)../tools/NetCore21/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Core21>
<SwashbuckleSwaggerCliExe_Core31>dotnet "$(MSBuildThisFileDirectory)../tools/NetCore31/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Core31>
<SwashbuckleSwaggerCliExe_Net50>dotnet "$(MSBuildThisFileDirectory)../tools/Net50/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Net50>
<SwashbuckleSwaggerCliExe_Net60>dotnet "$(MSBuildThisFileDirectory)../tools/Net60/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Net60>
<SwashbuckleSwaggerCliExe_Net70>dotnet "$(MSBuildThisFileDirectory)../tools/Net70/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Net70>
<SwashbuckleSwaggerCliExe_Net80>dotnet "$(MSBuildThisFileDirectory)../tools/Net80/dotnet-swagger.dll"</SwashbuckleSwaggerCliExe_Net80>
</PropertyGroup>
</Project>
Expand Up @@ -6,7 +6,7 @@
<OutputType>Exe</OutputType>
<PackAsTool>true</PackAsTool>
<PackageId>Swashbuckle.AspNetCore.Cli</PackageId>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<ToolCommandName>swagger</ToolCommandName>
</PropertyGroup>

Expand Down
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -4,7 +4,7 @@
<AssemblyOriginatorKeyFile>Swashbuckle.AspNetCore.IntegrationTests.snk</AssemblyOriginatorKeyFile>
<NoWarn>$(NoWarn);8002</NoWarn>
<SignAssembly>true</SignAssembly>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<DocumentationFile>Swashbuckle.AspNetCore.SwaggerGen.Test.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/Basic/Basic.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/CliExample/CliExample.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<DotNetSwaggerPath>$([System.IO.Path]::Combine("..", "..", "..", "src", "Swashbuckle.AspNetCore.Cli", "bin", $(Configuration), $(TargetFramework), "dotnet-swagger.dll"))</DotNetSwaggerPath>
</PropertyGroup>

Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<DotNetSwaggerPath>$([System.IO.Path]::Combine("..", "..", "..", "src", "Swashbuckle.AspNetCore.Cli", "bin", $(Configuration), $(TargetFramework), "dotnet-swagger.dll"))</DotNetSwaggerPath>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/ConfigFromFile/ConfigFromFile.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/CustomUIConfig/CustomUIConfig.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/CustomUIIndex/CustomUIIndex.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/GenericControllers/GenericControllers.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/MinimalApp/MinimalApp.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DotNetSwaggerPath>$([System.IO.Path]::Combine("..", "..", "..", "src", "Swashbuckle.AspNetCore.Cli", "bin", $(Configuration), $(TargetFramework), "dotnet-swagger"))</DotNetSwaggerPath>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/MultipleVersions/MultipleVersions.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/NswagClientExample/NswagClientExample.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<DotNetSwaggerPath>$([System.IO.Path]::Combine("..", "..", "..", "src", "Swashbuckle.AspNetCore.Cli", "bin", $(Configuration), $(TargetFramework), "dotnet-swagger.dll"))</DotNetSwaggerPath>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/OAuth2Integration/OAuth2Integration.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/ReDoc/ReDoc.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/TestFirst/TestFirst.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down