diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..5890df8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +FROM mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm + +RUN wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \ + sudo dpkg -i packages-microsoft-prod.deb && \ + rm packages-microsoft-prod.deb + +RUN sudo apt-get update && \ + sudo apt-get install -y dotnet-sdk-7.0 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ec1c27f..f3ca024 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,10 +3,13 @@ { "name": "C# (.NET)", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm", + // "image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm", + "build": { + "dockerfile": "Dockerfile" + }, "features": { "ghcr.io/devcontainers-contrib/features/bash-command:1": {} - } + }, // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, @@ -23,7 +26,14 @@ // "postCreateCommand": "dotnet restore", // Configure tool-specific properties. - // "customizations": {}, + "customizations": { + "vscode": { + "extensions": [ + "ms-dotnettools.csharp", + "ms-dotnettools.csdevkit" + ] + } + } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" diff --git a/src/Basic.CompilerLog.UnitTests/ProgramTests.cs b/src/Basic.CompilerLog.UnitTests/ProgramTests.cs index edcd8f7..7ba66f9 100644 --- a/src/Basic.CompilerLog.UnitTests/ProgramTests.cs +++ b/src/Basic.CompilerLog.UnitTests/ProgramTests.cs @@ -283,6 +283,32 @@ public void ResponseAll() Assert.Contains("Program.cs", File.ReadAllLines(rsp)); } + [Fact] + public void ResponseMultiTarget() + { + var exitCode = RunCompLog($"rsp {Fixture.ClassLibMultiProjectPath}"); + Assert.Equal(Constants.ExitSuccess, exitCode); + Assert.True(File.Exists(Path.Combine(RootDirectory, @".complog", "classlibmulti-net6.0", "build.rsp"))); + Assert.True(File.Exists(Path.Combine(RootDirectory, @".complog", "classlibmulti-net7.0", "build.rsp"))); + } + + [Fact] + public void ResponseNoLogArgument() + { + var (exitCode, output) = RunCompLogEx($"rsp -o {RootDirectory}", Path.GetDirectoryName(Fixture.ConsoleProjectPath)!); + TestOutputHelper.WriteLine(output); + Assert.Equal(Constants.ExitSuccess, exitCode); + Assert.True(File.Exists(Path.Combine(RootDirectory, "console", "build.rsp"))); + } + + [Fact] + public void ResponseNoLogAvailable() + { + var dir = Root.NewDirectory("empty"); + var exitCode = RunCompLog($"rsp", dir); + Assert.Equal(Constants.ExitFailure, exitCode); + } + [Fact] public void ResponseHelp() { diff --git a/src/Basic.CompilerLog.UnitTests/SolutionFixture.cs b/src/Basic.CompilerLog.UnitTests/SolutionFixture.cs index fccfccc..a3ba2f2 100644 --- a/src/Basic.CompilerLog.UnitTests/SolutionFixture.cs +++ b/src/Basic.CompilerLog.UnitTests/SolutionFixture.cs @@ -29,6 +29,8 @@ public sealed class SolutionFixture : FixtureBase, IDisposable internal string ClassLibProjectPath { get; } + internal string ClassLibMultiProjectPath { get; } + internal string ConsoleWithDiagnosticsBinaryLogPath { get; } internal string ConsoleWithDiagnosticsProjectPath { get; } @@ -71,6 +73,22 @@ public SolutionFixture(IMessageSink messageSink) return Path.Combine(dir, "classlib.csproj"); }); + ClassLibMultiProjectPath = WithProject("classlibmulti", string (string dir) => + { + RunDotnetCommand("new classlib --name classlibmulti -o .", dir); + var projectFileContent = """ + + + net6.0;net7.0 + enable + enable + + + """; + File.WriteAllText(Path.Combine(dir, "classlibmulti.csproj"), projectFileContent, TestBase.DefaultEncoding); + return Path.Combine(dir, "classlibmulti.csproj"); + }); + string WithProject(string name, Func func) { var dir = Path.Combine(StorageDirectory, name); @@ -83,7 +101,7 @@ string WithProject(string name, Func func) ProjectPaths = builder.ToImmutableArray(); SolutionBinaryLogPath = Path.Combine(binlogDir, "msbuild.binlog"); - DotnetUtil.CommandOrThrow($"dotnet build -bl:{SolutionBinaryLogPath} -nr:false", StorageDirectory); + RunDotnetCommand($"build -bl:{SolutionBinaryLogPath} -nr:false", StorageDirectory); (RemovedConsoleProjectPath, RemovedBinaryLogPath) = CreateRemovedProject(); (ConsoleWithDiagnosticsProjectPath, ConsoleWithDiagnosticsBinaryLogPath) = CreateConsoleWithDiagnosticsProject(); @@ -96,7 +114,7 @@ string WithProject(string name, Func func) var projectPath = Path.Combine(dir, "removed-console.csproj"); var binlogFilePath = Path.Combine(binlogDir, "removed-console.binlog"); - DotnetUtil.CommandOrThrow($"dotnet build -bl:{binlogFilePath} -nr:false", dir); + RunDotnetCommand($"build -bl:{binlogFilePath} -nr:false", dir); Directory.Delete(dir, recursive: true); return (projectPath, binlogFilePath); } diff --git a/src/Basic.CompilerLog.UnitTests/TestBase.cs b/src/Basic.CompilerLog.UnitTests/TestBase.cs index 60a7e9b..ed2ca9c 100644 --- a/src/Basic.CompilerLog.UnitTests/TestBase.cs +++ b/src/Basic.CompilerLog.UnitTests/TestBase.cs @@ -56,7 +56,19 @@ protected void RunDotNet(string command, string? workingDirectory = null) protected void AddProjectProperty(string property, string? workingDirectory = null) { - DotnetUtil.AddProjectProperty(property, workingDirectory ?? RootDirectory); + workingDirectory ??= RootDirectory; + var projectFile = Directory.EnumerateFiles(workingDirectory, "*proj").Single(); + var lines = File.ReadAllLines(projectFile); + using var writer = new StreamWriter(projectFile, append: false); + foreach (var line in lines) + { + if (line.Contains("")) + { + writer.WriteLine(property); + } + + writer.WriteLine(line); + } } protected string GetBinaryLogFullPath(string? workingDirectory = null) => diff --git a/src/Basic.CompilerLog/Basic.CompilerLog.csproj b/src/Basic.CompilerLog/Basic.CompilerLog.csproj index 377d611..f9d3ca0 100644 --- a/src/Basic.CompilerLog/Basic.CompilerLog.csproj +++ b/src/Basic.CompilerLog/Basic.CompilerLog.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Basic.CompilerLog/Program.cs b/src/Basic.CompilerLog/Program.cs index 5611d52..c88783d 100644 --- a/src/Basic.CompilerLog/Program.cs +++ b/src/Basic.CompilerLog/Program.cs @@ -635,10 +635,10 @@ static string GetLogFilePathAfterBuild(string baseDirectory, string? buildFileNa } var tag = buildArgs.Any() ? "" : "-t:Rebuild"; - var args = $"build {path} -bl:build.binlog {tag} {string.Join(' ', buildArgs)}"; + var args = $"build {path} -bl:build.binlog -nr:false {tag} {string.Join(' ', buildArgs)}"; WriteLine($"Building {path}"); WriteLine($"dotnet {args}"); - var result = ProcessUtil.Run("dotnet", args, baseDirectory); + var result = DotnetUtil.Command(args, baseDirectory); WriteLine(result.StandardOut); WriteLine(result.StandardError); if (!result.Succeeded) diff --git a/src/Shared/DotnetUtil.cs b/src/Shared/DotnetUtil.cs index 55878bb..1fc7b0b 100644 --- a/src/Shared/DotnetUtil.cs +++ b/src/Shared/DotnetUtil.cs @@ -61,28 +61,4 @@ internal static ProcessResult Command(string args, string? workingDirectory = nu workingDirectory: workingDirectory, environment: env); } - - internal static void CommandOrThrow(string args, string? workingDirectory = null) - { - if (!Command(args, workingDirectory).Succeeded) - { - throw new Exception("Command failed"); - } - } - - internal static void AddProjectProperty(string property, string workingDirectory) - { - var projectFile = Directory.EnumerateFiles(workingDirectory, "*proj").Single(); - var lines = File.ReadAllLines(projectFile); - using var writer = new StreamWriter(projectFile, append: false); - foreach (var line in lines) - { - if (line.Contains("")) - { - writer.WriteLine(property); - } - - writer.WriteLine(line); - } - } }