diff --git a/documentation/general/dotnet-run-file.md b/documentation/general/dotnet-run-file.md index dfcb07822795..49a4946936d5 100644 --- a/documentation/general/dotnet-run-file.md +++ b/documentation/general/dotnet-run-file.md @@ -261,7 +261,6 @@ and can do that efficiently by stopping the search when it sees the first "C# to For a given `dotnet run file.cs`, we include directives from the current entry point file (`file.cs`) and all other non-entry-point C# files, specifically from all `Compile` items included in the project, no matter whether the `Compile` items are specified in some MSBuild code or inferred from `#:include`. -(Processing directives from other files is currently gated under a feature flag that can be enabled by setting the MSBuild property `ExperimentalFileBasedProgramEnableTransitiveDirectives=true`.) The order in which other files are processed is currently unspecified (can change across SDK versions) but deterministic (stable in a given SDK version). We do not limit these directives to appear only in entry point files because it allows: - a non-entry-point file like `Util.cs` to be self-contained and have all the `#:package`s it needs specified in it, diff --git a/src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs b/src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs index 65fd17f44bdb..2303d48b4c2e 100644 --- a/src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs +++ b/src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs @@ -693,7 +693,6 @@ public enum IncludeOrExcludeKind /// public sealed class IncludeOrExclude(in ParseInfo info) : Named(info) { - public const string ExperimentalFileBasedProgramEnableTransitiveDirectives = nameof(ExperimentalFileBasedProgramEnableTransitiveDirectives); public const string MappingPropertyName = "FileBasedProgramsItemMapping"; public static string DefaultMappingString => ".cs=Compile;.resx=EmbeddedResource;.json=None;.razor=Content"; diff --git a/src/Cli/Microsoft.DotNet.FileBasedPrograms/InternalAPI.Unshipped.txt b/src/Cli/Microsoft.DotNet.FileBasedPrograms/InternalAPI.Unshipped.txt index d3a08eaa3a3e..cb463f26bf99 100644 --- a/src/Cli/Microsoft.DotNet.FileBasedPrograms/InternalAPI.Unshipped.txt +++ b/src/Cli/Microsoft.DotNet.FileBasedPrograms/InternalAPI.Unshipped.txt @@ -1,4 +1,3 @@ -const Microsoft.DotNet.FileBasedPrograms.CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives = "ExperimentalFileBasedProgramEnableTransitiveDirectives" -> string! const Microsoft.DotNet.FileBasedPrograms.CSharpDirective.IncludeOrExclude.MappingPropertyName = "FileBasedProgramsItemMapping" -> string! const Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective = "ExperimentalFileBasedProgramEnableRefDirective" -> string! Microsoft.DotNet.FileBasedPrograms.CSharpDirective diff --git a/src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs b/src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs index 50f18abe9265..64797417230f 100644 --- a/src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs +++ b/src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs @@ -437,7 +437,6 @@ private void CheckDirectives( ErrorReporter reportError) { bool? refEnabled = null; - bool? transitiveEnabled = null; foreach (var directive in directives) { @@ -445,11 +444,6 @@ private void CheckDirectives( { CheckFlagEnabled(ref refEnabled, CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective, directive); } - - if (directive.Info.SourceFile.Path != EntryPointSourceFile.Path) - { - CheckFlagEnabled(ref transitiveEnabled, CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives, directive); - } } void CheckFlagEnabled(ref bool? flag, string flagName, CSharpDirective directive) diff --git a/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs b/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs index b06c4aae98f6..edf0e2c1841e 100644 --- a/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs +++ b/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs @@ -448,7 +448,6 @@ public void RefDirective_DuplicateFolderName_ViaInclude() <{CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective}>true - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true """); @@ -2715,8 +2714,7 @@ public void DeleteSource_WithIncludeDirective_Transitive() var testInstance = _testAssetsManager.CreateTestDirectory(); // Create entry point file with #:include directive - File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), $""" - #:property {CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}=true + File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """ #:include Util.cs Console.WriteLine("Test"); """); diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs index 26e16204fc0e..3a459765653b 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs @@ -1249,9 +1249,6 @@ public static class B """); File.WriteAllText(Path.Join(testInstance.Path, "Directory.Build.props"), $""" - - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true - @@ -4081,7 +4078,6 @@ public void RefDirective_DuplicateRefFromIncludedFiles() <{CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective}>true - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true """); @@ -4139,7 +4135,6 @@ public void RefDirective_DuplicateRefFromIncludedFiles_Subdirectories() <{CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective}>true - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true """); @@ -4204,7 +4199,6 @@ public void RefDirective_IncludeAndRefSameFile() <{CSharpDirective.Ref.ExperimentalFileBasedProgramEnableRefDirective}>true - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true """); @@ -4340,14 +4334,6 @@ public void IncludeDirective_Transitive() Directory.CreateDirectory(Path.Join(testInstance.Path, "dir1/dir2")); Directory.CreateDirectory(Path.Join(testInstance.Path, "dir3")); - File.WriteAllText(Path.Join(testInstance.Path, "dir1/Directory.Build.props"), $""" - - - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true - - - """); - var a = """ B.M(); """; @@ -4598,14 +4584,6 @@ public void IncludeDirective_UpToDate_ProjectReference() { var testInstance = _testAssetsManager.CreateTestDirectory(); - File.WriteAllText(Path.Join(testInstance.Path, "Directory.Build.props"), $""" - - - <{CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives}>true - - - """); - var libDir = Path.Join(testInstance.Path, "Lib"); Directory.CreateDirectory(libDir); @@ -4665,44 +4643,6 @@ class UtilClass Build(testInstance, BuildLevel.All, expectedOutput: expectedOutput, workDir: appDir); } - /// - /// Transitive directives (directives in non-entry-point files) are gated behind a feature flag. - /// - [Fact] - public void IncludeDirective_FeatureFlags() - { - var testInstance = _testAssetsManager.CreateTestDirectory(); - - File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """ - #!/usr/bin/env dotnet - #:include Util.cs - Console.WriteLine(Util.M()); - """); - - var utilPath = Path.Join(testInstance.Path, "Util.cs"); - File.WriteAllText(utilPath, """ - #:property DefineConstants=MY_CONST - static class Util { public static string M() => "Hello from Util"; } - """); - - new DotnetCommand(Log, "run", "Program.cs") - .WithWorkingDirectory(testInstance.Path) - .Execute() - .Should().Fail() - .And.HaveStdErr($""" - {DirectiveError(utilPath, 1, Resources.ExperimentalFeatureDisabled, CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives)} - - {CliCommandStrings.RunCommandException} - """); - - new DotnetCommand(Log, "run", "Program.cs") - .WithWorkingDirectory(testInstance.Path) - .WithEnvironmentVariable(CSharpDirective.IncludeOrExclude.ExperimentalFileBasedProgramEnableTransitiveDirectives, "true") - .Execute() - .Should().Pass() - .And.HaveStdOut("Hello from Util"); - } - [Fact] public void IncludeDirective_CustomMapping() {