diff --git a/.ado/publish.yml b/.ado/publish.yml index 2f481fb6..e7ca17e4 100644 --- a/.ado/publish.yml +++ b/.ado/publish.yml @@ -14,7 +14,7 @@ trigger: none parameters: # Matrix with target build platforms. # x86 versions are not supported by Native AOT. - # Use net9.0 as the latest stable version. + # Use net10.0 as the latest stable version. - name: buildMatrix type: object default: @@ -81,6 +81,13 @@ parameters: os: windows TargetRuntime: win-x64 DotNetVersion: net9.0 + - Name: win_x64_net100 + Pool: + name: Azure-Pipelines-1ESPT-ExDShared + vmImage: windows-latest + os: windows + TargetRuntime: win-x64 + DotNetVersion: net10.0 - Name: osx_x64_net90 Pool: name: Azure Pipelines @@ -88,6 +95,13 @@ parameters: os: macOS TargetRuntime: osx-x64 DotNetVersion: net9.0 + - Name: osx_x64_net100 + Pool: + name: Azure Pipelines + vmImage: macos-14 + os: macOS + TargetRuntime: osx-x64 + DotNetVersion: net10.0 - Name: osx_arm64_net90 Pool: name: Azure Pipelines @@ -95,6 +109,13 @@ parameters: os: macOS TargetRuntime: osx-arm64 DotNetVersion: net9.0 + - Name: osx_arm64_net100 + Pool: + name: Azure Pipelines + vmImage: macos-14-arm64 + os: macOS + TargetRuntime: osx-arm64 + DotNetVersion: net10.0 - Name: linux_x64_net90 Pool: name: Azure-Pipelines-1ESPT-ExDShared @@ -102,6 +123,13 @@ parameters: os: linux TargetRuntime: linux-x64 DotNetVersion: net9.0 + - Name: linux_x64_net100 + Pool: + name: Azure-Pipelines-1ESPT-ExDShared + image: ubuntu-latest + os: linux + TargetRuntime: linux-x64 + DotNetVersion: net10.0 resources: repositories: @@ -144,7 +172,7 @@ extends: cancelTimeoutInMinutes: 45 # to allow more time to collect CodeQL debug info. variables: - DotNetMoniker: net9.0 + DotNetMoniker: net10.0 ${{ if and( variables.DisableOsxArm64CodeQL, eq( MatrixEntry.TargetRuntime, 'osx-arm64' )) }}: ONEES_ENFORCED_CODEQL_ENABLED: false @@ -243,6 +271,13 @@ extends: packageType: sdk version: 8.0.x + - ${{ if eq( MatrixEntry.DotNetVersion, 'net9.0' ) }}: + - task: UseDotNet@2 + displayName: Install .Net 9.0.x + inputs: + packageType: sdk + version: 9.0.x + - task: UseDotNet@2 displayName: Install .NET SDK using global.json inputs: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d1e0ac0..3740c75f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,13 +12,15 @@ jobs: strategy: matrix: os: [ windows-latest, macos-latest, ubuntu-latest ] - dotnet-version: [ net472, net8.0, net9.0] + dotnet-version: [ net472, net8.0, net9.0, net10.0] node-version: [ 18.x, 22.x ] configuration: [ Release ] exclude: - # Exclude Node 18.x on .NET < 9, to thin the matrix. + # Exclude Node 18.x on .NET < 10, to thin the matrix. - dotnet-version: net8.0 node-version: 18.x + - dotnet-version: net9.0 + node-version: 18.x - dotnet-version: net472 node-version: 18.x # Exclude .NET 4.x on non-Windows OS. @@ -46,6 +48,11 @@ jobs: with: dotnet-version: 9.0.x + - name: Setup .NET 10 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 10.0.x + - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: @@ -62,7 +69,7 @@ jobs: # limit-access-to-actor: true - name: Upload build artifacts - if: matrix.dotnet-version == 'net9.0' && matrix.node-version == '22.x' + if: matrix.dotnet-version == 'net10.0' && matrix.node-version == '22.x' uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}-${{ matrix.configuration }}-packages diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 68e66ffe..ffcc9033 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -47,16 +47,16 @@ jobs: # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs # queries: security-extended,security-and-quality - - name: Setup .NET 9 + - name: Setup .NET 10 if: matrix.language == 'csharp' uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Build C# if: matrix.language == 'csharp' - run: dotnet build -f:net9.0 -p:Configuration=Debug -p:NBGV_GitEngine=Disabled - # Just build the .NET 9 target framework; other targets would be redundant for CodeQL. + run: dotnet build -f:net10.0 -p:Configuration=Debug -p:NBGV_GitEngine=Disabled + # Just build the .NET 10 target framework; other targets would be redundant for CodeQL. # Disable git-versioning to prevent the shallow clone from causing build errors. - name: Perform CodeQL Analysis diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index aec23d34..cc78b9c3 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -42,7 +42,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Setup Pages uses: actions/configure-pages@v4 diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index f422070d..c9ae9214 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -18,13 +18,15 @@ jobs: strategy: matrix: # This must be kept in sync with the PR build matrix. os: [ windows-latest, macos-latest, ubuntu-latest ] - dotnet-version: [ net472, net8.0, net9.0] + dotnet-version: [ net472, net8.0, net9.0, net10.0] node-version: [ 18.x, 22.x ] configuration: [ Release ] exclude: - # Exclude Node 18.x on .NET < 9, to thin the matrix. + # Exclude Node 18.x on .NET < 10, to thin the matrix. - dotnet-version: net8.0 node-version: 18.x + - dotnet-version: net9.0 + node-version: 18.x - dotnet-version: net472 node-version: 18.x # Exclude .NET 4.x on non-Windows OS. diff --git a/.npmrc b/.npmrc index 145551ea..39c49602 100644 --- a/.npmrc +++ b/.npmrc @@ -1,8 +1,7 @@ # DO NOT SPECIFY AUTHENTICATION CREDENTIALS IN THIS FILE. # It should only be used to configure NPM registry sources. -# Use ADO public NPM registry to be complient +# Use ADO public NPM registry to be compliant # Additional registries should be added as upstreams instead of being added here. -registry=https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/npm/registry/ -always-auth=true \ No newline at end of file +registry=https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/npm/registry/ \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3b7fea61..41b95d03 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -46,7 +46,7 @@ "-c", "Release", "-f", - "net9.0", + "net10.0", "--", "--filter", "*.NonAot.*" diff --git a/README-DEV.md b/README-DEV.md index e45ca179..0915a268 100644 --- a/README-DEV.md +++ b/README-DEV.md @@ -25,7 +25,7 @@ dotnet pack ``` This produces both nuget and npm packages (for the current platform only) in the `out/pkg` directory. It uses `Debug` configuration by default, which is slower but allows for -[debugging](#debugging). Append `-c Relase` to change the configuration. +[debugging](#debugging). Append `-c Release` to change the configuration. ## Test ```bash diff --git a/bench/README.md b/bench/README.md index 245eba29..c5dd9dee 100644 --- a/bench/README.md +++ b/bench/README.md @@ -9,21 +9,21 @@ though the "Dynamic" benchmarks are CLR-only. ### Run all benchmarks ``` -dotnet run -c Release -f net9.0 --filter * +dotnet run -c Release -f net10.0 --filter * ``` ### Run only CLR or only AOT benchmarks ``` -dotnet run -c Release -f net9.0 --filter *clr.* -dotnet run -c Release -f net9.0 --filter *aot.* +dotnet run -c Release -f net10.0 --filter *clr.* +dotnet run -c Release -f net10.0 --filter *aot.* ``` ### Run a specific benchmark ``` -dotnet run -c Release -f net9.0 --filter *clr.CallDotnetFunction +dotnet run -c Release -f net10.0 --filter *clr.CallDotnetFunction ``` ### List benchmarks ``` -dotnet run -c Release -f net9.0 --list flat +dotnet run -c Release -f net10.0 --list flat ``` diff --git a/docs/features/type-definitions.md b/docs/features/type-definitions.md index c0500f9e..3d2ce4b5 100644 --- a/docs/features/type-definitions.md +++ b/docs/features/type-definitions.md @@ -43,7 +43,7 @@ The `node-api-dotnet-generator` npm package is a standalone command-line tool th | Parameter | Alias | Description | |---------------|-------|-------------| | `--asssembly` | `-a` | Required path to the assembly file for which type definitions are to be generated. -| `--framework` | `-f` | Target framework moniker of system assembly dependencies, e.g. `net8.0`. Defaults to the .NET runtime version used when invoking the tool (currently .NET 8). +| `--framework` | `-f` | Target framework moniker of system assembly dependencies, e.g. `net10.0`. Defaults to the .NET runtime version used when invoking the tool (currently .NET 10). | `--pack` | `-p` | Application targeting pack(s) to check when resolving system assembly dependencies. Defaults to `Microsoft.NETCore.App`. May be specified more than once. Add the `Microsoft.AspNetCore.App` targeting pack for an ASP.NET app, or `Microsoft.WindowsDesktop.App` for a Windows desktop app. | `--reference` | `-r` | Path to an assembly that is referenced by the primary assembly. System assemblies are located automatically via the targeting packs and do not need to be specified separately. All other referenced assemblies must be provided. May be specified more than once. | `--typedefs` | `-t` | Required path to output generated type definitions (`.d.ts`) file. diff --git a/docs/scenarios/js-dotnet-dynamic.md b/docs/scenarios/js-dotnet-dynamic.md index 7c7d1c43..953e134c 100644 --- a/docs/scenarios/js-dotnet-dynamic.md +++ b/docs/scenarios/js-dotnet-dynamic.md @@ -81,7 +81,7 @@ For examples of this scenario, see one of these directories in the repo: const dotnet = require('node-api-dotnet/net8.0'); ``` ::: - Currently the supported target frameworks are `net472`, `net8.0`, and `net9.0`. + Currently the supported target frameworks are `net472`, `net8.0`, `net9.0`, and `net10.0`. 4. Load one or more .NET packages using the generated `.js` files: ::: code-group diff --git a/docs/scenarios/js-dotnet-module.md b/docs/scenarios/js-dotnet-module.md index e829a6ac..08b04808 100644 --- a/docs/scenarios/js-dotnet-module.md +++ b/docs/scenarios/js-dotnet-module.md @@ -86,7 +86,7 @@ For a minimal example of this scenario, see const dotnet = require('node-api-dotnet/net8.0'); ``` ::: - Currently the supported target frameworks are `net472`, `net8.0`, and `net9.0`. + Currently the supported target frameworks are `net472`, `net8.0`, `net9.0`, and `net10.0`. 7. Load your .NET module assembly from its path using the `dotnet.require()` function: ```JavaScript diff --git a/global.json b/global.json index b3db90e6..a5175004 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.100", + "version": "10.0.100", "allowPrerelease": true, "rollForward": "latestFeature" } diff --git a/src/NodeApi.Generator/NodeApi.Generator.csproj b/src/NodeApi.Generator/NodeApi.Generator.csproj index 7825a59f..cb09593e 100644 --- a/src/NodeApi.Generator/NodeApi.Generator.csproj +++ b/src/NodeApi.Generator/NodeApi.Generator.csproj @@ -10,7 +10,7 @@ true true false - major + major diff --git a/src/NodeApi.Generator/NodeApi.Generator.targets b/src/NodeApi.Generator/NodeApi.Generator.targets index 3c572c62..1d1f4709 100644 --- a/src/NodeApi.Generator/NodeApi.Generator.targets +++ b/src/NodeApi.Generator/NodeApi.Generator.targets @@ -29,7 +29,7 @@ Resolves NodeApi source-generator (analyzer) assemblies. The recommended practice is to build analyzers targeting only .NET Standard 2.0, and place them in a special "analyzers" directory in the package where they are found automatically. But this package contains separate targets for .NET Standard 2.0, .NET Framework 4.x, - and .NET 6.0 (and later) in the "lib" directory. This task chooses the correct target based on the currnet MSBuild process's .NET version + and .NET 8.0 (and later) in the "lib" directory. This task chooses the correct target based on the currnet MSBuild process's .NET version (NOT the current target framework), and adds the assemblies to the Analyzer item group. --> diff --git a/src/NodeApi/Runtime/PooledBuffer.cs b/src/NodeApi/Runtime/PooledBuffer.cs index d4a234db..597f1235 100644 --- a/src/NodeApi/Runtime/PooledBuffer.cs +++ b/src/NodeApi/Runtime/PooledBuffer.cs @@ -52,11 +52,8 @@ private PooledBuffer(ArrayPool pool, int length, int bufferMinimumLength) public void Dispose() { - if (_pool != null) - { - _pool.Return(Buffer!); - _pool = null; - } + _pool?.Return(Buffer!); + _pool = null; } #endif diff --git a/src/node-api-dotnet/index.d.ts b/src/node-api-dotnet/index.d.ts index 253683bd..4501684d 100644 --- a/src/node-api-dotnet/index.d.ts +++ b/src/node-api-dotnet/index.d.ts @@ -27,7 +27,7 @@ * const dotnet = require('node-api-dotnet/net8.0'); * ``` * ::: - * Currently the supported target frameworks are `net472`, `net8.0`, and `net9.0`. + * Currently the supported target frameworks are `net472`, `net8.0`, `net9.0`, and `net10.0`. * @module node-api-dotnet */ declare module 'node-api-dotnet' { diff --git a/test/TestBuilder.cs b/test/TestBuilder.cs index d24a1d28..047decf4 100644 --- a/test/TestBuilder.cs +++ b/test/TestBuilder.cs @@ -177,10 +177,10 @@ public static void BuildProject( { if (GetNoBuild()) return; - string workingDirectory = Path.GetDirectoryName(logFilePath)!; + string workingDirectory = Path.GetDirectoryName(projectFilePath)!; if (target != "Publish") { - WriteCurrentFrameworkGlobalJson(workingDirectory); + WriteCurrentFrameworkGlobalJson(workingDirectory, projectFilePath); } using StreamWriter logWriter = new(File.Open( @@ -213,10 +213,21 @@ public static void BuildProject( WorkingDirectory = workingDirectory, }; - if (Environment.Version.Major == 8) + // Prevent nested dotnet invocations from inheriting the current host path from the + // parent dotnet process, which can cause host/runtime mismatches when SDK selection + // rolls forward to a newer major version. + if (Environment.Version.Major != 4) { - // Prevent the launched build from using the same MSBuild SDK that was used to run the test. - startInfo.Environment["MSBuildSDKsPath"] = ""; + startInfo.Environment.Remove("MSBuildSDKsPath"); + startInfo.Environment.Remove("DOTNET_HOST_PATH"); + startInfo.Environment.Remove("DOTNET_ROOT"); + startInfo.Environment.Remove("DOTNET_ROOT(x86)"); + startInfo.Environment.Remove("DOTNET_ROOT_X86"); + startInfo.Environment.Remove("DOTNET_ROOT(x64)"); + startInfo.Environment.Remove("DOTNET_ROOT_X64"); + startInfo.Environment.Remove("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR"); + startInfo.Environment.Remove("DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR"); + startInfo.Environment.Remove("DOTNET_MSBUILD_SDK_RESOLVER_SDKS_VER"); } logWriter.WriteLine($"dotnet {startInfo.Arguments}"); @@ -241,7 +252,9 @@ public static void BuildProject( } } - private static void WriteCurrentFrameworkGlobalJson(string workingDirectory) + private static void WriteCurrentFrameworkGlobalJson( + string workingDirectory, + string projectFilePath) { Version frameworkVersion = Environment.Version; if (frameworkVersion.Major == 4) @@ -272,8 +285,15 @@ private static void WriteCurrentFrameworkGlobalJson(string workingDirectory) } } """; - string globalJsonFilePath = Path.Combine(workingDirectory, "global.json"); - File.WriteAllText(globalJsonFilePath, globalJson); + + // SDK resolution for `dotnet build ` walks from the project directory, + // so write global.json both near logs and next to the generated project file. + string workingDirGlobalJsonFilePath = Path.Combine(workingDirectory, "global.json"); + File.WriteAllText(workingDirGlobalJsonFilePath, globalJson); + + string projectDirectory = Path.GetDirectoryName(projectFilePath)!; + string projectDirGlobalJsonFilePath = Path.Combine(projectDirectory, "global.json"); + File.WriteAllText(projectDirGlobalJsonFilePath, globalJson); } public static void RunNodeTestCase(