Skip to content

Commit

Permalink
DotNet command template
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Oct 30, 2024
1 parent ec2a4e2 commit 64ab4b0
Show file tree
Hide file tree
Showing 326 changed files with 19,202 additions and 2,414 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pure.DI check
name: CSharpInteractive check

on: [ push, pull_request ]

Expand Down
20 changes: 20 additions & 0 deletions .run/Get version.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Get version" type="DotNetProject" factoryName=".NET Project" folderName="Scripts">
<option name="EXE_PATH" value="$PROJECT_DIR$/CSharpInteractive/bin/Debug/CSharpInteractive.Tool/net8.0/dotnet-csi.dll" />
<option name="PROGRAM_PARAMETERS" value="--version" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Samples/Scripts" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/CSharpInteractive/CSharpInteractive.Tool.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
51 changes: 30 additions & 21 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
false)
};

new DotNetToolRestore().WithShortName("Restoring tools").Run().EnsureSuccess();
new DotNetToolRestore().Run().EnsureSuccess();

new DotNetClean()
.WithProject(solutionFile)
Expand Down Expand Up @@ -173,8 +173,9 @@
}
}

var uninstallTool = new DotNetCustom("tool", "uninstall", toolPackageId, "-g")
.WithShortName("Uninstalling tool");
var uninstallTool = new DotNetToolUninstall()
.WithPackage(toolPackageId)
.WithGlobal(true);

if (uninstallTool.Run(_ => { }).ExitCode != 0)
{
Expand All @@ -191,42 +192,49 @@
Environment.SetEnvironmentVariable("PATH", pathEnvVar);
}

var installTool = new DotNetCustom("tool", "install", toolPackageId, "-g", "--version", packageVersion.ToString(), "--add-source", Path.Combine(outputDir, "CSharpInteractive.Tool"))
.WithShortName("Installing tool");
await new DotNetBuild()
.WithProject(Path.Combine("Samples", "MySampleLib"))
.BuildAsync().EnsureSuccess();

var installTool = new DotNetToolInstall()
.WithPackage(toolPackageId)
.WithGlobal(true)
.WithVersion(packageVersion.ToString())
.AddSources(Path.Combine(outputDir, "CSharpInteractive.Tool"));

installTool.Run(output =>
{
output.Handled = true;
WriteLine(output.Line);
}).EnsureSuccess(_ => true);

new DotNetCustom("csi", "/?").WithShortName("Checking tool").Run().EnsureSuccess();
new DotNetCsi().WithVersion(true).WithShortName("Checking csi tool").Run().EnsureSuccess();

var uninstallTemplates = new DotNetCustom("new", "uninstall", templatesPackageId)
.WithShortName("Uninstalling template");
var uninstallTemplates = new DotNetNewUninstall()
.WithPackage(templatesPackageId);

uninstallTemplates.Run(output =>
{
output.Handled = true;
WriteLine(output.Line);
}).EnsureSuccess(_ => true);

var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
.WithShortName("Installing template");
var installTemplates = new DotNetNewInstall()
.WithPackage($"{templatesPackageId}::{packageVersion.ToString()}")
.AddSources(templateOutputDir);

installTemplates.WithShortName(installTemplates.ShortName).Run().EnsureSuccess();
installTemplates.Run().EnsureSuccess();
foreach (var framework in frameworks)
{
await CheckCompatibilityAsync(framework, packageVersion, defaultNuGetSource, outputDir);
}

if (!string.IsNullOrWhiteSpace(apiKey) && packageVersion.Release != "dev" && packageVersion.Release != "dev")
{
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources(defaultNuGetSource);
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSource(defaultNuGetSource);
foreach (var package in packages.Where(i => i.Publish))
{
push.WithPackage(package.Package)
.WithShortName($"Pushing {Path.GetFileName(package.Package)}")
.Build().EnsureSuccess();
}
}
Expand Down Expand Up @@ -269,27 +277,28 @@ async Task CheckCompatibilityAsync(
try
{
var sampleProjectDir = Path.Combine("Samples", "MySampleLib", "MySampleLib.Tests");
await new DotNetNew("build", $"--version={nuGetVersion}", "-T", framework, "--no-restore")
await new DotNetNew()
.WithTemplateName("build")
.WithNoRestore(true)
.WithArgs($"--version={nuGetVersion}", "-T", framework)
.WithWorkingDirectory(buildProjectDir)
.WithShortName($"Creating a new {sampleProjectName}")
.RunAsync().EnsureSuccess();

await new DotNetBuild()
.WithProject(buildProjectDir)
.WithSources(nuGetSource, Path.Combine(output, "CSharpInteractive"))
.WithShortName($"Building the {sampleProjectName}")
.BuildAsync().EnsureSuccess();

await new DotNetRun()
.WithProject(buildProjectDir)
.WithWorkingDirectory(buildProjectDir)
.WithNoRestore(true)
.WithNoBuild(true)
.WithWorkingDirectory(sampleProjectDir)
.WithShortName($"Running a build for the {sampleProjectName}")
.WithFramework(framework)
.RunAsync().EnsureSuccess();

await new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx"))
await new DotNetCsi()
.WithScript(Path.Combine(buildProjectDir, "Program.csx"))
.WithWorkingDirectory(sampleProjectDir)
.WithShortName($"Running a build as a C# script for the {sampleProjectName}")
.RunAsync().EnsureSuccess();
}
finally
Expand Down
11 changes: 8 additions & 3 deletions CSharpInteractive.HostApi/CSharpInteractive.HostApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@
</None>

<Compile Update="CommandLines.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CommandLines.tt</DependentUpon>
</Compile>

<Compile Update="CommandLines.cs">
<None Update="DotNetCommands.tt">
<LastGenOutput>DotNetCommands.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>

<Compile Update="DotNetCommands.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CommandLines.tt</DependentUpon>
<DependentUpon>DotNetCommands.tt</DependentUpon>
</Compile>
</ItemGroup>

Expand Down
Loading

0 comments on commit 64ab4b0

Please sign in to comment.