From 7f95687e5ea79409282d112d93889715403802e4 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 22 Aug 2025 11:07:50 +0200 Subject: [PATCH] Pack file-based apps as tools by default --- .../Run/VirtualProjectBuildingCommand.cs | 1 + .../Convert/DotnetProjectConvertTests.cs | 25 +++++++++++++++++-- .../CommandTests/Run/RunFileTests.cs | 5 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs index 632fc6f86541..3bcabeab3287 100644 --- a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs +++ b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs @@ -82,6 +82,7 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase new("ImplicitUsings", "enable"), new("Nullable", "enable"), new("PublishAot", "true"), + new("PackAsTool", "true"), ]); /// diff --git a/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs b/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs index 507d36c0da98..34adc6ac9d1a 100644 --- a/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs +++ b/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs @@ -58,9 +58,13 @@ public void SameAsTemplate() var dotnetProjectConvertProjectText = File.ReadAllText(dotnetProjectConvertProject); var dotnetNewConsoleProjectText = File.ReadAllText(dotnetNewConsoleProject); - // There are some differences: we add PublishAot=true and UserSecretsId. + // There are some differences: we add PublishAot=true, PackAsTool=true, and UserSecretsId. var patchedDotnetProjectConvertProjectText = dotnetProjectConvertProjectText - .Replace(" true" + Environment.NewLine, string.Empty); + .Replace(""" + true + true + + """, string.Empty); patchedDotnetProjectConvertProjectText = Regex.Replace(patchedDotnetProjectConvertProjectText, """ [^<]*<\/UserSecretsId>""" + Environment.NewLine, string.Empty); @@ -661,6 +665,7 @@ public void ProcessingSucceeds() enable enable true + true Program-* @@ -708,6 +713,7 @@ public void UserSecretsId_Overridden_ViaDirective(bool hasDirectiveBuildProps) enable enable true + true MyIdFromDirective @@ -747,6 +753,7 @@ public void UserSecretsId_Overridden_ViaDirectoryBuildProps() enable enable true + true @@ -791,6 +798,7 @@ public void UserSecretsId_Overridden_SameAsImplicit(bool hasDirective, bool hasD enable enable true + true {(hasDirective ? SecurityElement.Escape(implicitValue) : "Program-*")} @@ -822,6 +830,7 @@ public void Directives() enable enable true + true net472 preview @@ -852,6 +861,7 @@ public void Directives_AllDefaultOverridden() #:property TargetFramework=net472 #:property Nullable=disable #:property PublishAot=false + #:property PackAsTool=false #:property Custom=1 #:property ImplicitUsings=disable Console.WriteLine(); @@ -864,6 +874,7 @@ public void Directives_AllDefaultOverridden() net472 disable false + false 1 disable @@ -893,6 +904,7 @@ public void Directives_Variable() enable enable true + true MyValue @@ -930,6 +942,7 @@ public void Directives_DirectoryPath() enable enable true + true @@ -968,6 +981,7 @@ public void Directives_Separators() enable enable true + true One=a/b Two/a=b @@ -1077,6 +1091,7 @@ public void Directives_Escaping() enable enable true + true <test"> @@ -1111,6 +1126,7 @@ public void Directives_Whitespace() enable enable true + true Value "My package with spaces" @@ -1137,6 +1153,7 @@ public void Directives_BlankLines() enable enable true + true @@ -1202,6 +1219,7 @@ public void Directives_AfterToken() enable enable true + true 1 2 @@ -1248,6 +1266,7 @@ public void Directives_AfterIf() enable enable true + true 1 2 @@ -1291,6 +1310,7 @@ public void Directives_Comments() enable enable true + true 1 2 @@ -1398,6 +1418,7 @@ public void Directives_VersionedSdkFirst() enable enable true + true diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs index 3ecc85f05580..634ed52a3e46 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs @@ -1695,7 +1695,6 @@ public void Pack() var testInstance = _testAssetsManager.CreateTestDirectory(); var programFile = Path.Join(testInstance.Path, "MyFileBasedTool.cs"); File.WriteAllText(programFile, """ - #:property PackAsTool=true Console.WriteLine($"Hello; EntryPointFilePath set? {AppContext.GetData("EntryPointFilePath") is string}"); #if !DEBUG Console.WriteLine("Release config"); @@ -1742,7 +1741,6 @@ public void Pack_CustomPath() var testInstance = _testAssetsManager.CreateTestDirectory(); var programFile = Path.Join(testInstance.Path, "MyFileBasedTool.cs"); File.WriteAllText(programFile, """ - #:property PackAsTool=true #:property PackageOutputPath=custom Console.WriteLine($"Hello; EntryPointFilePath set? {AppContext.GetData("EntryPointFilePath") is string}"); """); @@ -3309,6 +3307,7 @@ public void Api() enable enable true + true false true false @@ -3379,6 +3378,7 @@ public void Api_Diagnostic_01() enable enable true + true false true false @@ -3446,6 +3446,7 @@ public void Api_Diagnostic_02() enable enable true + true false true false