Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fallout.Cli/Program.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static string SessionId
_ => throw new NotSupportedException($"{EnvironmentInfo.Platform} has no session id selector.")
};

private static AbsolutePath SessionFile => GlobalTemporaryDirectory / $"nuke-{SessionId}.dat";
private static AbsolutePath SessionFile => GlobalTemporaryDirectory / $"fallout-{SessionId}.dat";

private static int GetNextDirectory()
{
Expand Down
61 changes: 46 additions & 15 deletions src/Fallout.Cli/Program.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Fallout.Common;
using Fallout.Common.Execution;
using Fallout.Common.IO;
Expand All @@ -22,7 +24,7 @@ partial class Program
{
// ReSharper disable InconsistentNaming

private const string TARGET_FRAMEWORK = "net8.0";
private const string TARGET_FRAMEWORK = "net10.0";
private const string PROJECT_KIND = "9A19103F-16F7-4668-BE54-9A1E7A4F7556";

// ReSharper disable once CognitiveComplexity
Expand All @@ -38,9 +40,9 @@ public static int Setup(string[] args, AbsolutePath rootDirectory, AbsolutePath

#region Basic

var nukeLatestReleaseVersion = NuGetVersionResolver.GetLatestVersion(FalloutCommonPackageId, includePrereleases: false);
var nukeLatestPrereleaseVersion = NuGetVersionResolver.GetLatestVersion(FalloutCommonPackageId, includePrereleases: true);
var nukeLatestLocalVersion = NuGetPackageResolver.GetGlobalInstalledPackage(FalloutCommonPackageId, version: null, packagesConfigFile: null)
var falloutLatestReleaseVersion = NuGetVersionResolver.GetLatestVersion(FalloutCommonPackageId, includePrereleases: false);
var falloutLatestPrereleaseVersion = NuGetVersionResolver.GetLatestVersion(FalloutCommonPackageId, includePrereleases: true);
var falloutLatestLocalVersion = NuGetPackageResolver.GetGlobalInstalledPackage(FalloutCommonPackageId, version: null, packagesConfigFile: null)
?.Version.ToString();

if (rootDirectory == null)
Expand All @@ -61,24 +63,24 @@ public static int Setup(string[] args, AbsolutePath rootDirectory, AbsolutePath
ClearPreviousLine();
ShowInput("round_pushpin", "Build project location", buildProjectRelativeDirectory);

var nukeVersion = PromptForChoice("Which Fallout.Common version should be used?",
var falloutVersion = PromptForChoice("Which Fallout.Common version should be used?",
new[]
{
("latest release", nukeLatestReleaseVersion.GetAwaiter().GetResult()),
("latest prerelease", nukeLatestPrereleaseVersion.GetAwaiter().GetResult()),
("latest local", nukeLatestLocalVersion),
("latest release", falloutLatestReleaseVersion.GetAwaiter().GetResult()),
("latest prerelease", falloutLatestPrereleaseVersion.GetAwaiter().GetResult()),
("latest local", falloutLatestLocalVersion),
("same as global tool", typeof(Program).GetTypeInfo().Assembly.GetVersionText())
}
.Where(x => x.Item2 != null)
.Distinct(x => x.Item2)
.Select(x => (x.Item2, $"{x.Item2} ({x.Item1})")).ToArray());
ShowInput("gem_stone", "Fallout.Common version", nukeVersion);
ShowInput("gem_stone", "Fallout.Common version", falloutVersion);

var solutionFile = (AbsolutePath) PromptForChoice(
"Which solution should be the default?",
choices: new DirectoryInfo(rootDirectory)
.EnumerateFiles("*", SearchOption.AllDirectories)
.Where(x => x.FullName.EndsWithOrdinalIgnoreCase(".sln"))
.Where(x => x.FullName.EndsWithOrdinalIgnoreCase(".sln") || x.FullName.EndsWithOrdinalIgnoreCase(".slnx"))
.OrderByDescending(x => x.FullName)
.Select(x => (x, rootDirectory.GetRelativePathTo(x.FullName).ToString()))
.Concat((null, "None")).ToArray())?.FullName;
Expand All @@ -102,10 +104,22 @@ public static int Setup(string[] args, AbsolutePath rootDirectory, AbsolutePath

if (solutionFile != null)
{
var solutionFileContent = solutionFile.ReadAllLines().ToList();
var buildProjectFileRelative = solutionFile.Parent.GetWinRelativePathTo(buildProjectFile);
UpdateSolutionFileContent(solutionFileContent, buildProjectFileRelative, buildProjectGuid, buildProjectName);
solutionFile.WriteAllLines(solutionFileContent, Encoding.UTF8);
if (solutionFile.Extension.EqualsOrdinalIgnoreCase(".slnx"))
{
var solutionDocument = XDocument.Load(solutionFile);
UpdateSolutionXmlFileContent(solutionDocument, buildProjectFileRelative);

var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true };
using var writer = XmlWriter.Create(solutionFile, settings);
solutionDocument.Save(writer);
}
else
{
var solutionFileContent = solutionFile.ReadAllLines().ToList();
UpdateSolutionFileContent(solutionFileContent, buildProjectFileRelative, buildProjectGuid, buildProjectName);
solutionFile.WriteAllLines(solutionFileContent, Encoding.UTF8);
}
}

buildProjectFile.WriteAllLines(
Expand All @@ -118,7 +132,7 @@ public static int Setup(string[] args, AbsolutePath rootDirectory, AbsolutePath
ScriptDirectory = buildDirectory.GetWinRelativePathTo(WorkingDirectory),
TargetFramework = TARGET_FRAMEWORK,
TelemetryVersion = Telemetry.CurrentVersion,
NukeVersion = nukeVersion,
FalloutVersion = falloutVersion,
})));

(buildDirectory / "Directory.Build.props").WriteAllLines(GetTemplate("Directory.Build.props"));
Expand Down Expand Up @@ -176,12 +190,29 @@ internal static void UpdateSolutionFileContent(
"EndProject");
}

internal static void UpdateSolutionXmlFileContent(XDocument content, string buildProjectFileRelative)
{
var solutionElement = content.Root;
Assert.True(solutionElement?.Name == "Solution", "Could not find a root 'Solution' element in solution file");

// file uses forward slashes for paths on every platform
var path = buildProjectFileRelative.Replace(oldChar: '\\', newChar: '/');

if (solutionElement.Elements("Project").Any(x => x.GetAttributeValue("Path").EqualsOrdinalIgnoreCase(path)))
{
return;
}

var projectElement = new XElement("Project", new XAttribute("Path", path));
projectElement.Add(new XElement("Build", new XAttribute("Project", value: false)));
solutionElement.Add(projectElement);
}

internal static string[] GetTemplate(string templateName)
{
return ResourceUtility.GetResourceAllLines<Program>($"templates.{templateName}");
}


internal static void WriteBuildScripts(
AbsolutePath scriptDirectory,
AbsolutePath rootDirectory)
Expand Down
4 changes: 3 additions & 1 deletion src/Fallout.Cli/templates/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
<FalloutScriptDirectory>_SCRIPT_DIRECTORY_</FalloutScriptDirectory>
<FalloutTelemetryVersion>_TELEMETRY_VERSION_</FalloutTelemetryVersion>
<IsPackable>false</IsPackable>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<UseArtifactsOutput>false</UseArtifactsOutput>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fallout.Common" Version="_NUKE_VERSION_" />
<PackageReference Include="Fallout.Common" Version="_FALLOUT_VERSION_" />
<PackageDownload Include="GitVersion.Tool" Version="[5.8.0]" /> // GITVERSION
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Solution>
<Project Path="TestProject1/TestProject1.csproj" />
<Project Path="RELATIVE">
<Build Project="false" />
</Project>
</Solution>
26 changes: 26 additions & 0 deletions tests/Fallout.Cli.Specs/UpdateSolutionFileContentSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Fallout.Common.Utilities;
using VerifyXunit;
using Xunit;
Expand Down Expand Up @@ -70,4 +73,27 @@ public Task Test(int number, string input)
return Verifier.Verify(string.Join(Environment.NewLine, content))
.UseParameters(number);
}

[Theory]
[InlineData(
1,
"""
<Solution>
<Project Path="TestProject1/TestProject1.csproj" />
</Solution>
""")]
public Task TestXml(int number, string input)
{
var content = XDocument.Load(new StringReader(input));
Program.UpdateSolutionXmlFileContent(content, "RELATIVE");

var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true };
var stringStream = new StringWriter();
using var writer = XmlWriter.Create(stringStream, settings);
content.Save(writer);
writer.Flush();

return Verifier.Verify(stringStream.ToString())
.UseParameters(number);
}
}
Loading