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

Design-Time codegen using ToDotNet library #107

Closed
solvingj opened this issue Mar 17, 2019 · 1 comment
Closed

Design-Time codegen using ToDotNet library #107

solvingj opened this issue Mar 17, 2019 · 1 comment

Comments

@solvingj
Copy link

solvingj commented Mar 17, 2019

This fairly recent article describes the use of codegen in a build process:

https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-in-a-build-process?view=vs-2017

It is talking specifically about T4 templates which are separate from this project. However, from a Visual Studio/MSBuild perspective, this would seem the appropriate mechanism to generate C# classes just prior to the compilation of regular project sources, so that the generated sources can be compiled in. With that said, I don't see anywhere in the documentation discussing support for the use of JSchema ToDotNet functionality with MSBuild as part of Design-Time codegen.

Is this supported or planned?

@solvingj solvingj changed the title Appropriate way to execute as a "pre-build Execute codegen using ToDotNet library as a "pre-build" event Mar 17, 2019
@solvingj solvingj changed the title Execute codegen using ToDotNet library as a "pre-build" event Design-Time codegen using ToDotNet library Mar 17, 2019
@solvingj
Copy link
Author

solvingj commented Mar 24, 2019

I was able to take another approach and create a custom target as shown below.

Of note, it would be really amazing if the Nuget package included a first-class Json-To-Dotnet MSBuild Task. It would be very little additional effort.

https://natemcmaster.com/blog/2017/07/05/msbuild-task-in-nuget/

    <Target Name="GenerateOpenFolderSources" BeforeTargets="PrepareForBuild">
        <PropertyGroup>  
          <ToDotNetCLI>$(PkgMicrosoft_Json_Schema_ToDotNet)\tools\net461\Microsoft.Json.Schema.ToDotNet.Cli.exe</ToDotNetCLI>

          <SchemaDirectory>Resources</SchemaDirectory>
          <GenOutDir>$(MSBuildProjectDirectory)</GenOutDir>
          
          <Namespace>MyNamespace</Namespace>
          <ClassName>MyClass</ClassName>
          <MySchemaFile>$(SchemaDirectory)/myschema.json</MySchemaFile>
          <MySchemaName>MySchemaName</MySchemaName>

          </PropertyGroup>  
        <Exec Command="$(ToDotNetCLI) -f -n $(Namespace) -o $(GenOutDir) -r $(MySchemaName) -e $(MySchemaName) -s $(MySchemaFile)"/>
    </Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant