Repository navigation
Type definitions are loaded by IDE out of the box - #132122
Conversation
|
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. |
There was a problem hiding this comment.
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.tstowwwroot/_framework/dotnet.d.ts(instead ofwwwroot/dotnet.d.ts) whenWasmEmitTypeScriptDefinitions=true. - Ensure
dotnet.d.tsis published alongsidedotnet.jsunder the publishedwwwroot/_frameworkdirectory. - Update WASM build tests/bundle assertions to optionally expect
dotnet.d.tswhen 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. |
There was a problem hiding this comment.
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
_EnsureDotnetTypeScriptDefinitionsis gated on!Exists('$(_DotnetTypesDestPath)'), which meansdotnet.d.tswill never be refreshed once created. If the runtime pack’sdotnet.d.tschanges (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)')">
There was a problem hiding this comment.
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’sdotnet.d.tschanges (e.g., after upgrading the SDK/runtime pack), the project’swwwroot/_framework/dotnet.d.tswill 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)')">
There was a problem hiding this comment.
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 Removeonly excludeswwwroot\_framework\dotnet.d.ts. If a project previously built with an older SDK already has a stalewwwroot\dotnet.d.tson disk, the defaultwwwrootglob can still pick it up whenWasmEmitTypeScriptDefinitions=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>
There was a problem hiding this comment.
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
_DotnetTypesDestPathis redundant because the same property is (re)computed in_ResolveDotnetTypeScriptDefinitionPathsbefore_EnsureDotnetTypeScriptDefinitionsuses 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>
There was a problem hiding this comment.
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 Removeentries are conditioned onWasmEmitTypeScriptDefinitions=true, which means if the property is later turned off (or the file exists from a previous build),wwwroot/**globs can start picking updotnet.d.tsagain, 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.tsandwwwroot/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
There was a problem hiding this comment.
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
_EnsureDotnetTypeScriptDefinitionsonly hooksAfterTargets="PrepareForBuild", sodotnet publish /p:NoBuild=truewon’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
_DotnetTypesDestPathis 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 incrementalOutputsis meant to use. Consider defining_DotnetTypesDestDir/_DotnetTypesDestPathonce 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
PublishProjectas well) would help ensure thewwwroot/_framework/dotnet.d.tscopy 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);
|
Where is the |
Yes, it's this line: <_DotnetTypesSourcePath>$([MSBuild]::NormalizePath($(_RuntimePackNativeDir), 'dotnet.d.ts'))</_DotnetTypesSourcePath>When |
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`.
Follow-up for #120097.
The original PR was placing the definitions in
wwwroot, while the correspondingdotnet.jssource file is imported fromwwwroot/_framework. That prevented IDE from automatically resolving the types and required additional workarounds on the developer side.Fix:
Create
wwwroot/_frameworkduring build withdotnet.d.tsinside.How it works in practice
Intelisense-fixed.mp4