ScriptSourceGenerator 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package ScriptSourceGenerator --version 1.0.5                
NuGet\Install-Package ScriptSourceGenerator -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ScriptSourceGenerator" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ScriptSourceGenerator --version 1.0.5                
#r "nuget: ScriptSourceGenerator, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ScriptSourceGenerator as a Cake Addin
#addin nuget:?package=ScriptSourceGenerator&version=1.0.5

// Install ScriptSourceGenerator as a Cake Tool
#tool nuget:?package=ScriptSourceGenerator&version=1.0.5                

ScriptSourceGenerator

Nuget

This geneator can compile and run csx files and generate files from csx scripts using Roslyn scripting.

Usage

  • Add nuget package into your project Nuget
  • Add a .csx script file into project:
var httpClient = new HttpClient();
var result = await client.GetStringAsync("http://www.github.com");
  • Change .csx file Build Action property to C# analyzer additional file or modify csproj like this:
<ItemGroup>
	<None Remove="MyScript.csx" />
	<AdditionalFiles Include="MyScript.csx" />
</ItemGroup>
  • If you want to create files as an output, you can use global Output indexer property which is a StringBuilder:
Output["Github.html"].Append(result);
  • Even you can create .cs files to generate compile time source codes:
Output["MyModel.cs"].AppendLine("""
public class MyModel
{
""");
for(var i=0; i < 5; i++)
{
    Output["MyModel.cs"].AppendLine($$"""
        public string Prop{{i}} { get; set; } 
    """);
}

Output["MyModel.cs"].AppendLine("}");

and it will be generate this file:

public class MyModel
{
    public string Prop0 { get; set; }
    public string Prop1 { get; set; }
    public string Prop2 { get; set; }
    public string Prop3 { get; set; }
    public string Prop4 { get; set; }
}
  • To add assembly references and nuget references use #r directives:
#r "nuget:Microsoft.OpenApi.Readers/1.4.5"
#r "System.Net.Http"
using System;
using System.Net.Http;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Readers;

var httpClient = new HttpClient
{
    BaseAddress = new Uri("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/")
};

var stream = await httpClient.GetStreamAsync("master/examples/v3.0/petstore.yaml");

// Read V3 as YAML
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);

// Write V2 as JSON
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
Output["GeneratedModels.cs"].Append(outputString);
  • External csx files can be imported with #load directive
#load "AnotherFile.csx"
using AnotherNamespace.In.AnotherFile;
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 285 12/16/2022
1.0.5 262 12/16/2022
1.0.4 279 12/14/2022
1.0.3 263 12/13/2022
1.0.2 262 12/13/2022
1.0.1 269 12/12/2022
1.0.1-pre1 98 12/12/2022
1.0.0 272 12/12/2022