diff --git a/Directory.Build.props b/Directory.Build.props index 3556b512a08..857a884c2f2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -77,7 +77,7 @@ --> - net8.0 + net9.0 $(DefaultNetCoreTargetFramework) diff --git a/Directory.Packages.props b/Directory.Packages.props index 19c6deb856d..02c9a790a75 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -63,7 +63,6 @@ - diff --git a/NuGet.config b/NuGet.config index 7a818f5f188..b5e83791aff 100644 --- a/NuGet.config +++ b/NuGet.config @@ -67,7 +67,6 @@ - diff --git a/docs/ProjectsAndLayering.md b/docs/ProjectsAndLayering.md index e95f1b8efbe..d4cb0e8ec42 100644 --- a/docs/ProjectsAndLayering.md +++ b/docs/ProjectsAndLayering.md @@ -48,13 +48,13 @@ rzls [1] MS.AspNetCore.Razor.LanguageServer This project is shared between all layers (both compiler and tooling) to provide language support types for modern C# language features. -- Target Framework: `net8.0;netstandard2.0;net472` +- Target Framework: `net9.0;netstandard2.0;net472` - Projects: - Microsoft.AspNetCore.Razor.Utilities.Shared ### Compiler -- Target Framework: `net8.0;netstandard2.0` +- Target Framework: `net9.0;netstandard2.0` - Projects: - Microsoft.CodeAnalysis.Razor.Compiler @@ -63,14 +63,14 @@ This project is shared between all layers (both compiler and tooling) to provide These projects are referenced by most Razor tooling projects. Because of this, they target the broadest set of frameworks. -- Target Framework: `net8.0;netstandard2.0;net472` +- Target Framework: `net9.0;netstandard2.0;net472` - Projects: - Microsoft.AspNetCore.Razor.ProjectEngineHost - Microsoft.CodeAnalysis.Razor.Workspaces ### Razor Language Server -- Target Framework: `net8.0;net472` +- Target Framework: `net9.0;net472` - Projects: - Microsoft.AspNetCore.Razor.LanguageServer - Microsoft.AspNetCore.Razor.LanguageServer.Common @@ -78,7 +78,7 @@ target the broadest set of frameworks. ### Razor Language Server (rzls) -- Target Framework: `net8.0` +- Target Framework: `net9.0` - Projects: - rzls @@ -103,7 +103,7 @@ target the broadest set of frameworks. ### Miscellaneous / Test hosting -- Target Framework: net7.0 +- Target Framework: `net9.0` - Projects: - Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace @@ -111,30 +111,30 @@ target the broadest set of frameworks. ### Shared test infra -- Microsoft.AspNetCore.Razor.Test.Common (`net8.0`;`net472`) +- Microsoft.AspNetCore.Razor.Test.Common (`net9.0`;`net472`) ### API Shims - Microsoft.AspNetCore.Razor.Test.ComponentShim (`netstandard2.0`) -- Microsoft.AspNetCore.Razor.Test.MvcShim (`net8.0`;`net472`) +- Microsoft.AspNetCore.Razor.Test.MvcShim (`net9.0`;`net472`) - Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib (`netstandard2.0`) -- Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X (`net8.0`;`net472`) -- Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X (`net8.0`;`net472`) +- Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X (`net9.0`;`net472`) +- Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X (`net9.0`;`net472`) ### Tooling Core Tests -- Microsoft.CodeAnalysis.Razor.Workspaces.Test (`net8.0`;`net472` - only on Windows) -- Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common (`net8.0`;`net472`) +- Microsoft.CodeAnalysis.Razor.Workspaces.Test (`net9.0`;`net472` - only on Windows) +- Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common (`net9.0`;`net472`) ### Language Server -- Microsoft.AspNetCore.Razor.LanguageServer.Common.Test (`net8.0`) -- Microsoft.AspNetCore.Razor.LanguageServer.Test (`net8.0-windows`) -- Microsoft.AspNetCore.Razor.LanguageServer.Test.Common (`net8.0`;`net472`) +- Microsoft.AspNetCore.Razor.LanguageServer.Common.Test (`net9.0`) +- Microsoft.AspNetCore.Razor.LanguageServer.Test (`net9.0-windows`) +- Microsoft.AspNetCore.Razor.LanguageServer.Test.Common (`net9.0`;`net472`) ### Roslyn OOP (for Visual Studio) Tests -- Microsoft.CodeAnalysis.Remote.Razor.Test (`net8.0`;`net472` - only on Windows) +- Microsoft.CodeAnalysis.Remote.Razor.Test (`net9.0`;`net472` - only on Windows) ### Visual Studio Code (Windows) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 6156e55f838..7cc86053e41 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -10,6 +10,8 @@ using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; @@ -22,8 +24,15 @@ public CodeGenerationIntegrationTest(bool designTime = false) : base(layer: TestProject.Layer.Compiler) { this.designTime = designTime; - BaseCompilation = BaseCompilation.AddReferences( - MetadataReference.CreateFromFile(typeof(TestTagHelperDescriptors).Assembly.Location)); + var testTagHelpers = CSharpCompilation.Create( + assemblyName: "Microsoft.AspNetCore.Razor.Language.Test", + syntaxTrees: + [ + CSharpSyntaxTree.ParseText(TestTagHelperDescriptors.Code), + ], + references: ReferenceUtil.AspNetLatestAll, + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + BaseCompilation = BaseCompilation.AddReferences(testTagHelpers.VerifyDiagnostics().EmitToImageReference()); } [IntegrationTestFact] diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs index 96d58b5f8dc..34fc03d46eb 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs @@ -215,7 +215,7 @@ public static IEnumerable EnumTagHelperDescriptors .Name("catch-all") .Metadata(PropertyName("CatchAll")) .AsEnum() - .TypeName($"{typeof(TestTagHelperDescriptors).FullName}.{nameof(MyEnum)}"), + .TypeName("Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestTagHelperDescriptors.MyEnum"), }), CreateTagHelperDescriptor( tagName: "input", @@ -227,7 +227,7 @@ public static IEnumerable EnumTagHelperDescriptors .Name("value") .Metadata(PropertyName("Value")) .AsEnum() - .TypeName($"{typeof(TestTagHelperDescriptors).FullName}.{nameof(MyEnum)}"), + .TypeName("Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestTagHelperDescriptors.MyEnum"), }), }; } @@ -644,9 +644,17 @@ private class TestType public string BoundProperty { get; set; } } - public enum MyEnum - { - MyValue, - MySecondValue - } + public static readonly string Code = """ + namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests + { + public class TestTagHelperDescriptors + { + public enum MyEnum + { + MyValue, + MySecondValue + } + } + } + """; } diff --git a/src/Compiler/perf/Microsoft.AspNetCore.Razor.Microbenchmarks.Generator/SampleApp/SampleApp.csproj b/src/Compiler/perf/Microsoft.AspNetCore.Razor.Microbenchmarks.Generator/SampleApp/SampleApp.csproj index a4bd750a33e..864c6308c8f 100644 --- a/src/Compiler/perf/Microsoft.AspNetCore.Razor.Microbenchmarks.Generator/SampleApp/SampleApp.csproj +++ b/src/Compiler/perf/Microsoft.AspNetCore.Razor.Microbenchmarks.Generator/SampleApp/SampleApp.csproj @@ -8,7 +8,7 @@ - net8.0 + net9.0 enable enable true diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs index 601d9fbfd4c..7596e3526ce 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources.cs @@ -62,7 +62,11 @@ public static byte[] GetResourceBytes(string name, string? folder = null) using var stream = GetResourceStream(name, folder); value = new byte[stream.Length]; +#if NETCOREAPP + stream.ReadExactly(value, 0, value.Length); +#else stream.Read(value, 0, value.Length); +#endif s_bytesMap.Add(key, value); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/StreamExtensions.NetCore.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/StreamExtensions.NetCore.cs index 81abc7a2a16..6e0897eafcc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/StreamExtensions.NetCore.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/StreamExtensions.NetCore.cs @@ -103,7 +103,7 @@ public static void WriteSize(this Stream stream, int length) public unsafe static int ReadSize(this Stream stream) { Span bytes = stackalloc byte[4]; - stream.Read(bytes); + stream.ReadExactly(bytes); return BitConverter.ToInt32(bytes); } } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs index 8c83d70f305..9ceab30b29c 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs @@ -31,7 +31,6 @@ internal class DirectiveCompletionItemProvider : IRazorCompletionItemProvider CSharpCodeParser.UsingDirectiveDescriptor }; - // Test accessor internal static IEnumerable MvcDefaultDirectives => s_mvcDefaultDirectives; internal static IEnumerable ComponentDefaultDirectives => s_componentDefaultDirectives; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs index 214efe87b4d..e86c686c056 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.Razor.Language; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj index dd983e0656d..d74202c9306 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj @@ -7,18 +7,12 @@ false true false - - $(NoWarn);IDE0073 - diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IDocumentSnapshotExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IDocumentSnapshotExtensions.cs index 62a90f11432..07713fe5259 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IDocumentSnapshotExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IDocumentSnapshotExtensions.cs @@ -57,5 +57,4 @@ public static Task GetGeneratedOutputAsync(this IDocumentSnap { return documentSnapshot.GetGeneratedOutputAsync(forceDesignTimeGeneratedOutput: false); } - } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs index 75455fd0a2c..2ef7a3224d5 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs @@ -1,4 +1,7 @@ -using System.Runtime.Serialization; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Runtime.Serialization; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Settings; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs index ba51627d53c..120685d419f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs @@ -1,4 +1,5 @@ -// Licensed under the MIT license. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. using System; using System.Buffers; diff --git a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/NonCapturingTimer.cs b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/NonCapturingTimer.cs new file mode 100644 index 00000000000..23bb7a90127 --- /dev/null +++ b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/NonCapturingTimer.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +// https://github.com/dotnet/runtime/blob/11c86d8acba2f248b3afb5e8594f5f41ceebf098/src/libraries/Common/src/Extensions/NonCapturingTimer/NonCapturingTimer.cs + +using System; +using System.Threading; + +namespace Microsoft.Extensions.Internal; + +// A convenience API for interacting with System.Threading.Timer in a way +// that doesn't capture the ExecutionContext. We should be using this (or equivalent) +// everywhere we use timers to avoid rooting any values stored in asynclocals. +internal static class NonCapturingTimer +{ + public static Timer Create(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period) + { + if (callback is null) + { + throw new ArgumentNullException(nameof(callback)); + } + + // Don't capture the current ExecutionContext and its AsyncLocals onto the timer + var restoreFlow = false; + try + { + if (!ExecutionContext.IsFlowSuppressed()) + { + ExecutionContext.SuppressFlow(); + restoreFlow = true; + } + + return new Timer(callback, state, dueTime, period); + } + finally + { + // Restore the current ExecutionContext + if (restoreFlow) + { + ExecutionContext.RestoreFlow(); + } + } + } +} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs index 6a5585a4bd2..62eced685aa 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/RazorTestResources.cs @@ -69,7 +69,11 @@ public static byte[] GetResourceBytes(string name, string? folder = null) using var stream = GetResourceStream(name, folder); value = new byte[stream.Length]; +#if NETCOREAPP + stream.ReadExactly(value, 0, value.Length); +#else stream.Read(value, 0, value.Length); +#endif s_bytesMap.Add(key, value);