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
5 changes: 4 additions & 1 deletion src/Cli/dotnet/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal static CommandBase CreateVirtualOrPhysicalCommand(
Func<MSBuildArgs, string?, CommandBase> createPhysicalCommand,
IEnumerable<Option> optionsToUseWhenParsingMSBuildFlags,
ParseResult parseResult,
string? msbuildPath = null)
string? msbuildPath = null,
Func<MSBuildArgs, MSBuildArgs>? transformer = null)
{
var args = parseResult.GetValue(catchAllUserInputArgument) ?? [];
LoggerUtility.SeparateBinLogArguments(args, out var binLogArgs, out var nonBinLogArgs);
Expand All @@ -32,11 +33,13 @@ internal static CommandBase CreateVirtualOrPhysicalCommand(
CommonOptions.GetTargetResultOption,
CommonOptions.GetResultOutputFileOption,
]);
msbuildArgs = transformer?.Invoke(msbuildArgs) ?? msbuildArgs;
return configureVirtualCommand(msbuildArgs, Path.GetFullPath(arg));
}
else
{
var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([.. forwardedArgs, .. args], [.. optionsToUseWhenParsingMSBuildFlags]);
msbuildArgs = transformer?.Invoke(msbuildArgs) ?? msbuildArgs;
return createPhysicalCommand(msbuildArgs, msbuildPath);
}
}
Expand Down
29 changes: 15 additions & 14 deletions src/Cli/dotnet/Commands/Pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
NoRestore = noRestore,
NoCache = true,
},
(msbuildArgs, msbuildPath) =>
{
ReleasePropertyProjectLocator projectLocator = new(parseResult, MSBuildPropertyNames.PACK_RELEASE,
new ReleasePropertyProjectLocator.DependentCommandOptions(
nonBinLogArgs,
parseResult.HasOption(PackCommandParser.ConfigurationOption) ? parseResult.GetValue(PackCommandParser.ConfigurationOption) : null
)
);
return new PackCommand(
msbuildArgs.CloneWithAdditionalProperties(projectLocator.GetCustomDefaultConfigurationValueIfSpecified()),
noRestore,
msbuildPath);
},
(msbuildArgs, msbuildPath) => new PackCommand(
msbuildArgs,
noRestore,
msbuildPath),
optionsToUseWhenParsingMSBuildFlags:
[
CommonOptions.PropertiesOption,
Expand All @@ -70,7 +61,17 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
PackCommandParser.VerbosityOption,
],
parseResult,
msbuildPath);
msbuildPath,
(msbuildArgs) =>
{
ReleasePropertyProjectLocator projectLocator = new(parseResult, MSBuildPropertyNames.PACK_RELEASE,
new ReleasePropertyProjectLocator.DependentCommandOptions(
nonBinLogArgs,
parseResult.HasOption(PackCommandParser.ConfigurationOption) ? parseResult.GetValue(PackCommandParser.ConfigurationOption) : null
)
);
return msbuildArgs.CloneWithAdditionalProperties(projectLocator.GetCustomDefaultConfigurationValueIfSpecified());
});
}

private static LogLevel MappingVerbosityToNugetLogLevel(VerbosityOptions? verbosity)
Expand Down
22 changes: 12 additions & 10 deletions src/Cli/dotnet/Commands/Publish/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,25 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
NoRestore = noRestore,
NoCache = true,
},
(msbuildArgs, msbuildPath) => {
(msbuildArgs, msbuildPath) => new PublishCommand(
msbuildArgs: msbuildArgs,
noRestore: noRestore,
msbuildPath: msbuildPath
),
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, PublishCommandParser.TargetOption, PublishCommandParser.VerbosityOption],
parseResult,
msbuildPath,
(msbuildArgs) =>
{
var options = new ReleasePropertyProjectLocator.DependentCommandOptions(
nonBinLogArgs,
parseResult.HasOption(PublishCommandParser.ConfigurationOption) ? parseResult.GetValue(PublishCommandParser.ConfigurationOption) : null,
parseResult.HasOption(PublishCommandParser.FrameworkOption) ? parseResult.GetValue(PublishCommandParser.FrameworkOption) : null
);
var projectLocator = new ReleasePropertyProjectLocator(parseResult, MSBuildPropertyNames.PUBLISH_RELEASE, options);
var releaseModeProperties = projectLocator.GetCustomDefaultConfigurationValueIfSpecified();
return new PublishCommand(
msbuildArgs: msbuildArgs.CloneWithAdditionalProperties(releaseModeProperties),
noRestore: noRestore,
msbuildPath: msbuildPath
);
},
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, PublishCommandParser.TargetOption, PublishCommandParser.VerbosityOption],
parseResult,
msbuildPath
return msbuildArgs.CloneWithAdditionalProperties(releaseModeProperties);
}
);
}

Expand Down
9 changes: 8 additions & 1 deletion src/Cli/dotnet/ReleasePropertyProjectLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Collections.ObjectModel;
using System.CommandLine;
using System.Diagnostics;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.DotNet.Cli.Commands.Run;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.NET.Build.Tasks;
using Microsoft.VisualStudio.SolutionPersistence.Model;
Expand Down Expand Up @@ -108,7 +110,12 @@ DependentCommandOptions commandOptions
{
foreach (string arg in _slnOrProjectArgs.Append(Directory.GetCurrentDirectory()))
{
if (IsValidProjectFilePath(arg))
if (VirtualProjectBuildingCommand.IsValidEntryPointPath(arg))
{
return new VirtualProjectBuildingCommand(Path.GetFullPath(arg), MSBuildArgs.FromProperties(globalProps))
.CreateProjectInstance(ProjectCollection.GlobalProjectCollection);
}
else if (IsValidProjectFilePath(arg))
{
return TryGetProjectInstance(arg, globalProps);
}
Expand Down
16 changes: 15 additions & 1 deletion test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ public void Publish()
new DirectoryInfo(publishDir).Sub("Program")
.Should().Exist()
.And.NotHaveFilesMatching("*.deps.json", SearchOption.TopDirectoryOnly); // no deps.json file for AOT-published app

new RunExeCommand(Log, Path.Join(publishDir, "Program", $"Program{Constants.ExeSuffix}"))
.Execute()
.Should().Pass()
.And.HaveStdOut("""
Hello from Program
Release config
""");
}

[Fact]
Expand Down Expand Up @@ -1689,6 +1697,9 @@ public void Pack()
File.WriteAllText(programFile, """
#:property PackAsTool=true
Console.WriteLine($"Hello; EntryPointFilePath set? {AppContext.GetData("EntryPointFilePath") is string}");
#if !DEBUG
Console.WriteLine("Release config");
#endif
""");

// Run unpacked.
Expand Down Expand Up @@ -1719,7 +1730,10 @@ public void Pack()
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello; EntryPointFilePath set? False");
.And.HaveStdOutContaining("""
Hello; EntryPointFilePath set? False
Release config
""");
}

[Fact]
Expand Down