Skip to content

Type definitions are loaded by IDE out of the box - #132122

Merged
ilonatommy merged 9 commits into
mainfrom
improve-120097
Aug 12, 2026
Merged

ilonatommy merged 9 commits into
mainfrom
improve-120097

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Follow-up for #120097.

The original PR was placing the definitions in wwwroot, while the corresponding dotnet.js source file is imported from wwwroot/_framework. That prevented IDE from automatically resolving the types and required additional workarounds on the developer side.

Fix:
Create wwwroot/_framework during build with dotnet.d.ts inside.

image

How it works in practice

Intelisense-fixed.mp4

@ilonatommy ilonatommy self-assigned this Aug 11, 2026
Copilot AI lite review requested due to automatic review settings August 11, 2026 09:08
@ilonatommy
ilonatommy requested a review from maraf as a code owner August 11, 2026 09:08
@ilonatommy ilonatommy added the arch-wasm WebAssembly architecture label Aug 11, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@ilonatommy ilonatommy added this to the 11.0.0 milestone Aug 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the WebAssembly SDK’s handling of dotnet.d.ts so TypeScript definitions are placed beside runtime assets under wwwroot/_framework and are included appropriately in publish output, with corresponding test updates.

Changes:

  • Copy dotnet.d.ts to wwwroot/_framework/dotnet.d.ts (instead of wwwroot/dotnet.d.ts) when WasmEmitTypeScriptDefinitions=true.
  • Ensure dotnet.d.ts is published alongside dotnet.js under the published wwwroot/_framework directory.
  • Update WASM build tests/bundle assertions to optionally expect dotnet.d.ts when enabled.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs Extends expected runtime file sets to include dotnet.d.ts when tests opt in.
src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs Updates the TypeScript definitions test to validate the new _framework location and publish behavior.
src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs Excludes dotnet.d.ts from boot-json entry validation (it’s not a boot resource).
src/mono/wasm/Wasm.Build.Tests/BrowserStructures/MSBuildOptions.cs Adds a test harness flag to indicate when dotnet.d.ts should be expected.
src/mono/wasm/build/WasmApp.Common.targets Updates documentation comment describing the new output location.
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets Implements new build/publish targets to place dotnet.d.ts under wwwroot/_framework and include it in publish output.

Copilot AI review requested due to automatic review settings August 11, 2026 09:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1307

  • _EnsureDotnetTypeScriptDefinitions is gated on !Exists('$(_DotnetTypesDestPath)'), which means dotnet.d.ts will never be refreshed once created. If the runtime pack’s dotnet.d.ts changes (e.g., SDK/runtime update), projects will keep a stale copy unless the file is manually deleted. Consider switching to a proper incremental target keyed off the source file (Inputs/Outputs) rather than skipping solely based on destination existence.
  <Target Name="_EnsureDotnetTypeScriptDefinitions" 
          DependsOnTargets="ResolveRuntimePackAssets"
          AfterTargets="PrepareForBuild"
          Outputs="$(_DotnetTypesDestPath)"
          Condition="'$(WasmEmitTypeScriptDefinitions)' == 'true' and !Exists('$(_DotnetTypesDestPath)')">

Copilot AI review requested due to automatic review settings August 11, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1307

  • The _EnsureDotnetTypeScriptDefinitions target is currently gated on !Exists('$(_DotnetTypesDestPath)'), which makes the copy effectively “one-shot”. If the runtime pack’s dotnet.d.ts changes (e.g., after upgrading the SDK/runtime pack), the project’s wwwroot/_framework/dotnet.d.ts will never be refreshed, leaving stale typings.

Consider making this target properly incremental based on source→dest timestamps/content (Inputs/Outputs), and rely on Copy SkipUnchangedFiles for the common no-op case, rather than skipping solely because the destination already exists.

  <Target Name="_EnsureDotnetTypeScriptDefinitions" 
          DependsOnTargets="ResolveRuntimePackAssets"
          AfterTargets="PrepareForBuild"
          Outputs="$(_DotnetTypesDestPath)"
          Condition="'$(WasmEmitTypeScriptDefinitions)' == 'true' and !Exists('$(_DotnetTypesDestPath)')">

Copilot AI review requested due to automatic review settings August 11, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1296

  • The Content Remove only excludes wwwroot\_framework\dotnet.d.ts. If a project previously built with an older SDK already has a stale wwwroot\dotnet.d.ts on disk, the default wwwroot glob can still pick it up when WasmEmitTypeScriptDefinitions=true, reintroducing the publish/content-item issue this block is trying to prevent.
  <ItemGroup Condition="'$(WasmEmitTypeScriptDefinitions)' == 'true'">
    <Content Remove="wwwroot\_framework\dotnet.d.ts" />
  </ItemGroup>

@Hedbugg Hedbugg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice

Copilot AI review requested due to automatic review settings August 11, 2026 10:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1301

  • The top-level PropertyGroup defining _DotnetTypesDestPath is redundant because the same property is (re)computed in _ResolveDotnetTypeScriptDefinitionPaths before _EnsureDotnetTypeScriptDefinitions uses it. Keeping two definitions makes it harder to reason about which value is in effect and can lead to future edits updating only one location.
  <!-- Ensure dotnet.d.ts is beside dotnet.js in wwwroot/_framework for TypeScript development experience when enabled -->
  <PropertyGroup>
    <_DotnetTypesDestPath>$([MSBuild]::NormalizePath($([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), 'wwwroot', '_framework')), 'dotnet.d.ts'))</_DotnetTypesDestPath>

Copilot AI review requested due to automatic review settings August 11, 2026 10:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1297

  • The Content Remove entries are conditioned on WasmEmitTypeScriptDefinitions=true, which means if the property is later turned off (or the file exists from a previous build), wwwroot/** globs can start picking up dotnet.d.ts again, potentially changing build/publish inputs unexpectedly. Since this file is always build-generated, consider removing it from @(Content) unconditionally to keep behavior stable regardless of the property’s current value.
  <ItemGroup Condition="'$(WasmEmitTypeScriptDefinitions)' == 'true'">
    <Content Remove="wwwroot\dotnet.d.ts" />
    <Content Remove="wwwroot\_framework\dotnet.d.ts" />
  </ItemGroup>

src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs:358

  • This comment is now slightly misleading: the test is checking both wwwroot/_framework/dotnet.d.ts and wwwroot/dotnet.d.ts, not just the wwwroot root. Updating the wording will keep the test intent clear.
            // Verify dotnet.d.ts is not in wwwroot after creation

Copilot AI review requested due to automatic review settings August 11, 2026 10:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1321

  • _EnsureDotnetTypeScriptDefinitions only hooks AfterTargets="PrepareForBuild", so dotnet publish /p:NoBuild=true won’t run this target even though it’s a publish invocation. If the intent is “build/publish”, consider also hooking into the publish pipeline (e.g., BeforeTargets="PrepareForPublish") to cover NoBuild publishes.
  <Target Name="_EnsureDotnetTypeScriptDefinitions"
          DependsOnTargets="_ResolveDotnetTypeScriptDefinitionPaths"
          AfterTargets="PrepareForBuild"
          Inputs="$(_DotnetTypesSourcePath)"
          Outputs="$(_DotnetTypesDestPath)"
          Condition="'$(WasmEmitTypeScriptDefinitions)' == 'true'">

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets:1302

  • _DotnetTypesDestPath is computed twice (once in the standalone <PropertyGroup> and again in _ResolveDotnetTypeScriptDefinitionPaths). This duplication makes it easy for the two definitions to drift and obscures which value the target’s incremental Outputs is meant to use. Consider defining _DotnetTypesDestDir/_DotnetTypesDestPath once in the property group and letting the resolve target focus only on the runtime-pack source path.

This issue also appears on line 1316 of the same file.

  <!-- Ensure dotnet.d.ts is beside dotnet.js in wwwroot/_framework for TypeScript development experience when enabled -->
  <PropertyGroup>
    <_DotnetTypesDestPath>$([MSBuild]::NormalizePath($([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), 'wwwroot', '_framework')), 'dotnet.d.ts'))</_DotnetTypesDestPath>
  </PropertyGroup>

src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs:366

  • The updated logic is intended to run on both build and publish, but this test still only exercises the build path. Adding a publish variant (e.g., parameterize build vs publish and call PublishProject as well) would help ensure the wwwroot/_framework/dotnet.d.ts copy behaves the same across both entrypoints.
            // Build to trigger the _EnsureDotnetTypeScriptDefinitions target during the build phase
            BuildProject(info, config, new BuildOptions());

            // Verify dotnet.d.ts presence in the project's wwwroot/_framework directory after build
            bool fileExists = File.Exists(dotnetDtsWwwrootPath);

Copilot AI review requested due to automatic review settings August 11, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@ArcadeMode ArcadeMode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great 👍

@pavelsavara

Copy link
Copy Markdown
Member

Where is the dotnet.d.ts sourced from ? Is it from the runtime pack ?

@ilonatommy

Copy link
Copy Markdown
Member Author

Where is the dotnet.d.ts sourced from ? Is it from the runtime pack ?

Yes, it's this line:

<_DotnetTypesSourcePath>$([MSBuild]::NormalizePath($(_RuntimePackNativeDir), 'dotnet.d.ts'))</_DotnetTypesSourcePath>

When WsmEmitTypeScriptDefinitions=true the build copies the file from runtime pack to the app project.

@ilonatommy
ilonatommy merged commit 3265efb into main Aug 12, 2026
48 checks passed
@ilonatommy
ilonatommy deleted the improve-120097 branch August 12, 2026 09:02
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-rc1 Aug 13, 2026
ilonatommy added a commit that referenced this pull request Aug 14, 2026
Cleanup
#132122 (comment)

1) The original change belonged to net11 previews so it's a subject to
change, we don't need to provide a way to clean "wwwroot\dotnet.d.ts" on
upgrade.

2) The new target added in #132122
used public `WasmEmitTypeScriptDefinitions`, not internal
`_WasmEmitTypeScriptDefinitions`.
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-Build-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants