Skip to content

Commit

Permalink
Add NSwag.MSBuild.CodeGeneration package (#1659)
Browse files Browse the repository at this point in the history
* Add NSwag.MSBuild.CodeGeneration package
- #1587, #1588

* Correct typo in 01_Build.bat

* Use Microsoft.Extensions.ApiDescription.Design version from https://dotnet.myget.org
- see https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.Extensions.ApiDescription.Design
- version ranges don't work with preview releases, see NuGet/Home#912
- users need the [aspnetcore-dev](https://dotnet.myget.org/gallery/aspnetcore-dev) feed to get this package

* Revert part of "Add NSwag.MSBuild.CodeGeneration package"
- remove unnecessary files added in commit cf65d85.

* Add `netcoreapp2.2` support in NSwag.MSBuild.CodeGeneration.targets

* nit: add NSwag.MSBuild.CodeGeneration files to solution
- VS also automatically corrected the NSwag.AssemblyLoader.Tests project type in the solution

* Update version

* Update Microsoft.Extensions.ApiDescription.Design package version
- this preview package is available on NuGet.org
  • Loading branch information
dougbu authored and RicoSuter committed Nov 27, 2018
1 parent db3b834 commit a174a2c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/01_Build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ xcopy "%~dp0/../src/NSwag.ConsoleCore/bin/release/netcoreapp2.1/publish" "%~dp0/

REM Package nuspecs
"%~dp0/nuget.exe" pack "%~dp0/../src/NSwag.MSBuild/NSwag.MSBuild.nuspec" || goto :error
"%~dp0/nuget.exe" pack "%~dp0/../src/NSwag.MSBuild.CodeGeneration/NSwag.MSBuild.CodeGeneration.nuspec" || goto :error
"%~dp0/nuget.exe" pack "%~dp0/../src/NSwagStudio.Chocolatey/NSwagStudio.nuspec" || goto :error

goto :EOF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>NSwag.MSBuild.CodeGeneration</id>
<version>12.0.0</version>
<authors>Rico Suter</authors>
<owners>Rico Suter</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</licenseUrl>
<projectUrl>https://github.com/NSwag/NSwag</projectUrl>
<iconUrl>https://raw.githubusercontent.com/NSwag/NSwag/master/assets/NuGetIcon.png</iconUrl>
<description>NSwag: The Swagger API toolchain for .NET and TypeScript</description>
<tags>Swagger Documentation WebApi AspNet TypeScript CodeGen</tags>
<developmentDependency>true</developmentDependency>
<dependencies>
<dependency id="Microsoft.Extensions.ApiDescription.Design" version="0.1.0-preview1-10773" />
<dependency id="NSwag.MSBuild" version="12.0.0" />
</dependencies>
<references />
</metadata>
<files>
<file src="NSwag.MSBuild.CodeGeneration.targets" target="build" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project>
<PropertyGroup>
<_NSwagcommand>$(NSwagExe)</_NSwagcommand>
<_NSwagcommand Condition="'$(MSBuildRuntimeType)' == 'Core'">$(NSwagExe_Core20)</_NSwagcommand>
</PropertyGroup>

<ItemDefinitionGroup>
<CurrentServiceProjectReference>
<GenerateNSwagDocumentOptions />
<Configuration />
<Platform />
</CurrentServiceProjectReference>
<CurrentServiceFileReference>
<GenerateNSwagCSharpOptions />
<GenerateNSwagTypeScriptOptions />
</CurrentServiceFileReference>
</ItemDefinitionGroup>

<!-- ServiceProjectReference support -->

<Target Name="GenerateNSwagDocument">
<ItemGroup>
<!-- @(CurrentServiceProjectReference) item group will never contain more than one item. -->
<CurrentServiceProjectReference Update="@(CurrentServiceProjectReference)">
<Command>$(NSwagExe)</Command>
<Command Condition="'%(Platform)' == 'x86'">$(NSwagExe_x86)</Command>
<Command Condition="'%(TargetFramework)' == 'netcoreapp1.0'">$(NSwagExe_Core10)</Command>
<Command Condition="'%(TargetFramework)' == 'netcoreapp1.1'">$(NSwagExe_Core11)</Command>
<Command Condition="'%(TargetFramework)' == 'netcoreapp2.0'">$(NSwagExe_Core20)</Command>
<Command Condition="'%(TargetFramework)' == 'netcoreapp2.1'">$(NSwagExe_Core21)</Command>
<Command Condition="'%(TargetFramework)' == 'netcoreapp2.2'">$(NSwagExe_Core21)</Command>
<Configuration Condition="'%(Configuration)' == ''">$(Configuration)</Configuration>
<GenerateNSwagDocumentOptions
Condition="'%(GenerateNSwagDocumentOptions)' == ''">$(GenerateNSwagDocumentDefaultOptions)</GenerateNSwagDocumentOptions>
</CurrentServiceProjectReference>
<CurrentServiceProjectReference Update="@(CurrentServiceProjectReference)">
<Command>%(Command) aspnetcore2swagger /NoBuild:true /output:%(DocumentPath) /Project:%(FullPath)</Command>
</CurrentServiceProjectReference>
<CurrentServiceProjectReference Update="@(CurrentServiceProjectReference)">
<Command>%(Command) /Configuration:%(Configuration) /TargetFramework:%(TargetFramework)</Command>
</CurrentServiceProjectReference>
<CurrentServiceProjectReference Update="@(CurrentServiceProjectReference)">
<Command>%(Command) %(GenerateNSwagDocumentOptions)</Command>
</CurrentServiceProjectReference>
</ItemGroup>

<Message Importance="high" Text="%0AGenerateNSwagDocument:" />
<Message Importance="high" Text=" %(CurrentServiceProjectReference.Command)" />
<Exec Command="%(CurrentServiceProjectReference.Command)"
IgnoreExitCode="$([System.IO.File]::Exists('%(DocumentPath)'))" />
</Target>

<!-- ServiceFileReference support for C# -->

<Target Name="GenerateNSwagCSharp">
<ItemGroup>
<!-- @(CurrentServiceFileReference) item group will never contain more than one item. -->
<CurrentServiceFileReference Update="@(CurrentServiceFileReference)">
<Command>$(_NSwagcommand) swagger2csclient /className:%(ClassName) /namespace:%(Namespace)</Command>
<GenerateNSwagCSharpOptions
Condition="'%(GenerateNSwagCSharpOptions)' == ''">$(GenerateNSwagCSharpDefaultOptions)</GenerateNSwagCSharpOptions>
</CurrentServiceFileReference>
<CurrentServiceFileReference Update="@(CurrentServiceFileReference)">
<Command>%(Command) /input:%(FullPath) /output:%(OutputPath) %(GenerateNSwagCSharpOptions)</Command>
</CurrentServiceFileReference>
</ItemGroup>

<Message Importance="high" Text="%0AGenerateNSwagCSharp:" />
<Message Importance="high" Text=" %(CurrentServiceFileReference.Command)" />
<Exec Command="%(CurrentServiceFileReference.Command)"
IgnoreExitCode="$([System.IO.File]::Exists('%(OutputPath)'))" />
</Target>

<!-- ServiceFileReference support for TypeScript -->

<Target Name="GenerateNSwagTypeScript">
<ItemGroup>
<!-- @(CurrentServiceFileReference) item group will never contain more than one item. -->
<CurrentServiceFileReference Update="@(CurrentServiceFileReference)">
<Command>$(_NSwagcommand) swagger2tsclient /className:%(ClassName) /namespace:%(Namespace)</Command>
<GenerateNSwagTypeScriptOptions
Condition="'%(GenerateNSwagTypeScriptOptions)' == ''">$(GenerateNSwagTypeScriptDefaultOptions)</GenerateNSwagTypeScriptOptions>
</CurrentServiceFileReference>
<CurrentServiceFileReference Update="@(CurrentServiceFileReference)">
<Command>%(Command) /input:%(FullPath) /output:%(OutputPath) %(GenerateNSwagTypeScriptOptions)</Command>
</CurrentServiceFileReference>
</ItemGroup>

<Message Importance="high" Text="%0AGenerateNSwagTypeScript:" />
<Message Importance="high" Text=" %(CurrentServiceFileReference.Command)" />
<Exec Command="%(CurrentServiceFileReference.Command)"
IgnoreExitCode="$([System.IO.File]::Exists('%(OutputPath)'))" />
</Target>
</Project>
7 changes: 7 additions & 0 deletions src/NSwag.sln
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSwag.SwaggerGeneration.Asp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSwag.AssemblyLoader.Tests", "NSwag.AssemblyLoader.Tests\NSwag.AssemblyLoader.Tests.csproj", "{1853262B-6D39-477B-872A-8B5473FE74BB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NSwag.MSBuild.CodeGeneration", "NSwag.MSBuild.CodeGeneration", "{E6E40935-0C79-480B-BF29-8C493AC7E518}"
ProjectSection(SolutionItems) = preProject
NSwag.MSBuild.CodeGeneration\NSwag.MSBuild.CodeGeneration.nuspec = NSwag.MSBuild.CodeGeneration\NSwag.MSBuild.CodeGeneration.nuspec
NSwag.MSBuild.CodeGeneration\NSwag.MSBuild.CodeGeneration.targets = NSwag.MSBuild.CodeGeneration\NSwag.MSBuild.CodeGeneration.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1024,6 +1030,7 @@ Global
{18386943-8FCC-4414-BBEF-A1CAB1E557A2} = {D8CC0D1C-8DAC-49FE-AA78-C028DC124DD5}
{FDD41017-91E2-4BD8-B827-F851BDEC6B6E} = {634E4ABD-29EC-4EB2-81EF-7E41D6D6F6E0}
{1853262B-6D39-477B-872A-8B5473FE74BB} = {634E4ABD-29EC-4EB2-81EF-7E41D6D6F6E0}
{E6E40935-0C79-480B-BF29-8C493AC7E518} = {DDBB05AC-B066-48C4-933C-034F401EBB6A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98FCEEE2-A45C-41E7-B2ED-1B14755E9067}
Expand Down

0 comments on commit a174a2c

Please sign in to comment.