Skip to content

Commit

Permalink
Use DotNet command template
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Oct 24, 2024
1 parent ec2a4e2 commit 7444ca6
Show file tree
Hide file tree
Showing 77 changed files with 10,872 additions and 1,417 deletions.
30 changes: 23 additions & 7 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@
Environment.SetEnvironmentVariable("PATH", pathEnvVar);
}

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

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

installTool.Run(output =>
Expand All @@ -202,7 +211,8 @@

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

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

uninstallTemplates.Run(output =>
Expand All @@ -211,7 +221,9 @@
WriteLine(output.Line);
}).EnsureSuccess(_ => true);

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

installTemplates.WithShortName(installTemplates.ShortName).Run().EnsureSuccess();
Expand All @@ -222,7 +234,7 @@

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)
Expand Down Expand Up @@ -269,7 +281,10 @@ 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();
Expand All @@ -281,9 +296,10 @@ async Task CheckCompatibilityAsync(
.BuildAsync().EnsureSuccess();

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

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
3,618 changes: 3,509 additions & 109 deletions CSharpInteractive.HostApi/CommandLines.cs

Large diffs are not rendered by default.

56 changes: 53 additions & 3 deletions CSharpInteractive.HostApi/CommandLines.tt
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
// ReSharper disable InconsistentNaming
namespace HostApi;

<#
var commandLineTypes = new[]
{
"CommandLine",

// Dotnet
"DotNetCustom",
"DotNet",
"DotNetExec",
"DotNetAddPackage",
"DotNetListPackage",
"DotNetRemovePackage",
"DotNetAddReference",
"DotNetListReference",
"DotNetRemoveReference",
"DotNetBuild",
"DotNetBuildServerShutdown",
"DotNetClean",
"DotNetCustom",
"DotNetDevCertsHttps",
"MSBuild",
"DotNetNew",
"DotNetNewList",
"DotNetNewSearch",
"DotNetNewDetails",
"DotNetNewInstall",
"DotNetNewUninstall",
"DotNetNewUpdate",
"DotNetNuGetDelete",
"DotNetNuGetLocalsClear",
"DotNetNuGetLocalsList",
"DotNetNuGetPush",
"DotNetNuGetAddSource",
"DotNetNuGetDisableSource",
"DotNetNuGetEnableSource",
"DotNetNuGetListSource",
"DotNetNuGetRemoveSource",
"DotNetNuGetUpdateSource",
"DotNetNuGetVerify",
"DotNetNuGetTrustList",
"DotNetNuGetTrustSync",
"DotNetNuGetTrustRemove",
"DotNetNuGetTrustAuthor",
"DotNetNuGetTrustRepository",
"DotNetNuGetTrustCertificate",
"DotNetNuGetTrustSource",
"DotNetNuGetSign",
"DotNetNuGetWhy",
"DotNetNuConfigGet",
"DotNetNuConfigSet",
"DotNetNuConfigUnset",
"DotNetNuConfigPaths",
"DotNetPackageSearch",
"DotNetPack",
"DotNetPublish",
"DotNetRestore",
"DotNetRun",
"DotNetSdkCheck",
"DotNetSlnList",
"DotNetSlnAdd",
"DotNetSlnRemove",
"DotNetStore",
"DotNetTest",
"DotNetToolInstall",
"DotNetToolList",
"DotNetToolRestore",
"MSBuild",
"DotNetToolRun",
"DotNetToolSearch",
"DotNetToolUninstall",
"DotNetToolUpdate",
"VSTest",

// Docker
Expand Down
22 changes: 22 additions & 0 deletions CSharpInteractive.HostApi/DotNetBlameDumpType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace HostApi;

/// <summary>
/// The type of dump.
/// </summary>
public enum DotNetBlameDumpType
{
/// <summary>
/// None
/// </summary>
None,

/// <summary>
/// Full
/// </summary>
Full,

/// <summary>
/// Mini
/// </summary>
Mini
}
115 changes: 0 additions & 115 deletions CSharpInteractive.HostApi/DotNetBuild.cs

This file was deleted.

13 changes: 13 additions & 0 deletions CSharpInteractive.HostApi/DotNetBuildServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ public enum DotNetBuildServer
/// Razor build server
/// </summary>
Razor
}

internal static class DotNetBuildServerExtensions
{
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
public static string[] ToArgs(this IEnumerable<DotNetBuildServer> servers, string name, string collectionSeparator) =>
servers.Select(server => server switch
{
DotNetBuildServer.MSBuild => "--msbuild",
DotNetBuildServer.VbCsCompiler => "--vbcscompiler",
DotNetBuildServer.Razor => "--razor",
_ => throw new ArgumentOutOfRangeException()
}).ToArray();
}
Loading

0 comments on commit 7444ca6

Please sign in to comment.