Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to net9.0 #11000

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
-->
<Otherwise>
<PropertyGroup>
<DefaultNetCoreTargetFramework>net8.0</DefaultNetCoreTargetFramework>
<DefaultNetCoreTargetFramework>net9.0</DefaultNetCoreTargetFramework>
Copy link
Member Author

@jjonescz jjonescz Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess it's not that simple, parts that deploy to VS/VSCode need to stay on net8.0. I will at least extract the independent parts of this PR for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more of a gradual change, you could add net9 to the multi-targeting, and we can continue to change it as the needs of SDK/VS/VSCode change. There are some tradeoffs to making the multi-targeting conditional to being on a CI machine or not.

<DefaultNetCoreTargetFrameworks>$(DefaultNetCoreTargetFramework)</DefaultNetCoreTargetFrameworks>
</PropertyGroup>
</Otherwise>
Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(_MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(_MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(_MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.NonCapturingTimer.Sources" Version="5.0.0-preview.4.20205.1" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this source package would need more warnings to be suppressed with net9 (I'm not yet sure why, but some existing IDE* error codes started newly being reported with net9.0). It seems better to just include the one source file from this source package directly and make it conform to our editorconfig. I also fixed up some missing file headers that got missed because of the IDE0073 being ignored previously.

<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(_MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftExtensionsObjectPoolPackageVersion)" />
<PackageVersion Include="Microsoft.Internal.VisualStudio.Shell.Framework" Version="$(_MicrosoftVisualStudioShellPackagesVersion)" />
Expand Down
1 change: 0 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
</packageSource>
<packageSource key="dotnet6-transport">
<package pattern="microsoft.net.sdk.razor" />
<package pattern="microsoft.extensions.noncapturingtimer.sources" />
</packageSource>
<packageSource key="dotnet8">
<package pattern="microsoft.*" />
Expand Down
32 changes: 16 additions & 16 deletions docs/ProjectsAndLayering.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -63,22 +63,22 @@ 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
- Microsoft.AspNetCore.Razor.LanguageServer.Protocol

### Razor Language Server (rzls)

- Target Framework: `net8.0`
- Target Framework: `net9.0`
- Projects:
- rzls

Expand All @@ -103,38 +103,38 @@ target the broadest set of frameworks.

### Miscellaneous / Test hosting

- Target Framework: net7.0
- Target Framework: `net9.0`
- Projects:
- Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace

## Testing Layers

### 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assembly reference started failing due to now being net9.0 but others (via Basic.Reference.Assemblies) being net8.0.

Refactoring of the following file (TestTagHelperDescriptors.cs) is related to this.

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static IEnumerable<TagHelperDescriptor> 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",
Expand All @@ -227,7 +227,7 @@ public static IEnumerable<TagHelperDescriptor> EnumTagHelperDescriptors
.Name("value")
.Metadata(PropertyName("Value"))
.AsEnum()
.TypeName($"{typeof(TestTagHelperDescriptors).FullName}.{nameof(MyEnum)}"),
.TypeName("Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestTagHelperDescriptors.MyEnum"),
}),
};
}
Expand Down Expand Up @@ -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
}
}
}
""";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.Web"/>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void WriteSize(this Stream stream, int length)
public unsafe static int ReadSize(this Stream stream)
{
Span<byte> bytes = stackalloc byte[4];
stream.Read(bytes);
stream.ReadExactly(bytes);
return BitConverter.ToInt32(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ internal class DirectiveCompletionItemProvider : IRazorCompletionItemProvider
CSharpCodeParser.UsingDirectiveDescriptor
};


// Test accessor
internal static IEnumerable<DirectiveDescriptor> MvcDefaultDirectives => s_mvcDefaultDirectives;
internal static IEnumerable<DirectiveDescriptor> ComponentDefaultDirectives => s_componentDefaultDirectives;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@
<IsShippingPackage>false</IsShippingPackage>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<IsPackable Condition="'$(OS)' != 'Windows_NT'">false</IsPackable>
<!--
The NonCapturingTimer package is a source package, and the source files in there don't conform to our header
poilcy, so we have to ignore that error code for this project.
-->
<NoWarn>$(NoWarn);IDE0073</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="Microsoft.Extensions.NonCapturingTimer.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol.Extensions" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol.Internal" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ public static Task<RazorCodeDocument> GetGeneratedOutputAsync(this IDocumentSnap
{
return documentSnapshot.GetGeneratedOutputAsync(forceDesignTimeGeneratedOutput: false);
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down