Project generation by hand instead of using dotnet new

This commit is contained in:
Zev Spitz
2022-01-16 08:09:58 +02:00
parent cd0c4420e1
commit 7fabf7fa26
3 changed files with 29 additions and 10 deletions

View File

@@ -50,7 +50,7 @@ public sealed record ProcessResult(int ExitCode, string StdOut, string StdErr) {
public override string? ToString() => public override string? ToString() =>
StdOut + StdOut +
(StdOut is not (null or "") && ExitCode > 0 ? "\n" : "") + (StdOut is not (null or "") && ExitCode > 0 ? "\n" : "") +
(ExitCode > 0 ? (ExitCode != 0 ?
$"{ExitCode}\n{StdErr}" : $"{ExitCode}\n{StdErr}" :
""); "");
} }

View File

@@ -34,7 +34,7 @@ public record PortInfo(
(int?)null; (int?)null;
var gameName = var gameName =
parts.Length == 0 ? parts.Length <= 1 ?
null : null :
specialGameNames.TryGetValue(parts[1], out var specialName) ? specialGameNames.TryGetValue(parts[1], out var specialName) ?
specialName : specialName :

View File

@@ -184,18 +184,37 @@ void generateMissingSlns() {
void generateMissingProjs() { void generateMissingProjs() {
foreach (var item in infos.Where(x => !x.Projs.Any())) { foreach (var item in infos.Where(x => !x.Projs.Any())) {
var (langArg, langVersion) = item.Lang switch { // We can't use the dotnet command to create a new project using the built-in console template, because part of that template
"csharp" => ("\"C#\"", 10), // is a Program.cs / Program.vb file. If there already are code files, there's no need to add a new empty one; and
"vbnet" => ("\"VB\"", 16.9), // if there's already such a file, it might try to overwrite it.
var projText = item.Lang switch {
"csharp" => @"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
",
"vbnet" => @$"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>{item.GameName}</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>
",
_ => throw new InvalidOperationException() _ => throw new InvalidOperationException()
}; };
var result = RunProcess("dotnet", $"new console --language {langArg} --name {item.GameName}.{item.ProjExt} -o {item.LangPath} -f net6.0 --langversion {langVersion}");
WriteLine(result);
var projFullPath = Combine(item.LangPath, $"{item.GameName}.{item.ProjExt}"); var projFullPath = Combine(item.LangPath, $"{item.GameName}.{item.ProjExt}");
File.WriteAllText(projFullPath, projText);
if (item.Slns.Length == 1) { if (item.Slns.Length == 1) {
result = RunProcess("dotnet", $"sln {item.Slns[0]} add {projFullPath}"); var result = RunProcess("dotnet", $"sln {item.Slns[0]} add {projFullPath}");
WriteLine(result); WriteLine(result);
} }
} }