You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Microsoft.NET.Sdk.WebAssembly library project causes conflicting static web assets when referenced by another WebAssembly (Library or Executable) project.
Summary
I am trying to build a browser-based WebAssembly application consisting of two C# projects:
App — executable WebAssembly application
Lib — C# library referenced by App
Neither project uses Blazor, Razor, or any ASP.NET framework. The application is a plain .NET WebAssembly application running directly in the browser.
The library also needs to provide JavaScript/TypeScript files. JS files being in wwwroot are served as part of combined static web assets with specified StaticWebAssetBasePath. And TypeScript files ready to be consumed by App's TypeScript files.
To make JS assets from the library available to the application, I initially added:
<SdkName="Microsoft.NET.Sdk.StaticWebAssets" />
to the library project and it worked.
However, the library's TypeScript files depend on the dotnet.d.ts generated/provided by the .NET WebAssembly runtime, so I also need a reliable way for the library to obtain the appropriate dotnet.d.ts.
Then I changed my Lib project SDK from <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.WebAssembly"> and explicitly specified <OutputType>Library</OutputType>
With this setup both the flag and the workaround worked as expected.
However, this introduces a different problem.
When the Lib project is referenced by the App project, the build fails with an error similar to:
Conflicting assets with the same target path '_framework/Lib#[.{fingerprint}]!.pdb'.
For assets
'Identity: C:\...\Lemon\bin\Lemon.Web\Debug\net10.0-browser\wwwroot\_framework\Lemon.65s2n5qtql.pdb,
SourceType: Project,
SourceId: Lemon,
ContentRoot: C:\...\Lemon\bin\Lemon.Web\Debug\net10.0-browser\wwwroot\,
BasePath: /,
RelativePath: _framework/Lemon#[.{fingerprint}]!.pdb,
AssetKind: Build,
AssetMode: All,
AssetRole: Primary,
RelatedAsset: ,
AssetTraitName: WasmResource,
AssetTraitValue: symbol,
Fingerprint: 65s2n5qtql,
...
and
'Identity: C:\...\Lime\bin\Lime.Web\Debug\net10.0-browser\wwwroot\_framework\Lemon.65s2n5qtql.pdb,
SourceType: Computed,
SourceId: Lime,
ContentRoot: C:\...\Lime\bin\Lime.Web\Debug\net10.0-browser\wwwroot\,
BasePath: /,
RelativePath: _framework/Lemon#[.{fingerprint}]!.pdb,
AssetKind: Build,
AssetMode: All,
AssetRole: Primary,
...
'
from different projects.
The _framework/* files emitted by the WebAssembly SDK therefore become static web assets of the library. When the library is consumed by another WebAssembly application, those assets overlap with the assets produced by the consuming application.
Questions
Is using Microsoft.NET.Sdk.WebAssembly with:
<OutputType>Library</OutputType>
a supported way of creating a reusable WebAssembly library?
If so, is it expected that the SDK's generated _framework/* output becomes part of the library's Static Web Assets manifest?
More generally, what is the intended SDK/project setup for a plain .NET WebAssembly library that:
does not use Blazor/Razor,
contains C# code,
needs to ship JavaScript/TypeScript files through wwwroot,
needs to JSImport/JSExport from/to it's own js.
and can be referenced by another plain .NET WebAssembly application?
A WebAssembly library should be able to reference another WebAssembly library in the same way as an ordinary .NET library.
To work without the library's generated WebAssembly runtime/application assets being treated as independent static web assets that conflict with the consuming application's own _framework assets.
The library needs to be able to provide its own intentional web assets (for example .js), while its intermediate/generated WebAssembly files should not cause duplicate static-web-asset entries in the consuming application.
Description
Microsoft.NET.Sdk.WebAssemblylibrary project causes conflicting static web assets when referenced by another WebAssembly (Library or Executable) project.Summary
I am trying to build a browser-based WebAssembly application consisting of two C# projects:
App— executable WebAssembly applicationLib— C# library referenced byAppNeither project uses Blazor, Razor, or any ASP.NET framework. The application is a plain .NET WebAssembly application running directly in the browser.
The library also needs to provide JavaScript/TypeScript files. JS files being in wwwroot are served as part of combined static web assets with specified
StaticWebAssetBasePath. And TypeScript files ready to be consumed by App's TypeScript files.To make JS assets from the library available to the application, I initially added:
to the library project and it worked.
However, the library's TypeScript files depend on the
dotnet.d.tsgenerated/provided by the .NET WebAssembly runtime, so I also need a reliable way for the library to obtain the appropriatedotnet.d.ts.I read up on the topic and found:
dotnet.d.tstowwwrooton build/publish. #120097I tried both workaround (below) and attempt to use the flag
WasmEmitTypeScriptDefinitionswith .NET11 RC. Neither worked in Lib project.Then I changed my Lib project SDK from
<Project Sdk="Microsoft.NET.Sdk">to<Project Sdk="Microsoft.NET.Sdk.WebAssembly">and explicitly specified<OutputType>Library</OutputType>With this setup both the flag and the workaround worked as expected.
However, this introduces a different problem.
When the
Libproject is referenced by theAppproject, the build fails with an error similar to:The
_framework/*files emitted by the WebAssembly SDK therefore become static web assets of the library. When the library is consumed by another WebAssembly application, those assets overlap with the assets produced by the consuming application.Questions
Is using
Microsoft.NET.Sdk.WebAssemblywith:a supported way of creating a reusable WebAssembly library?
If so, is it expected that the SDK's generated
_framework/*output becomes part of the library's Static Web Assets manifest?More generally, what is the intended SDK/project setup for a plain .NET WebAssembly library that:
wwwroot,?
Reproduction Steps
Create projects like this:
App/
App.csproj
Lib/
Lib.csproj
App.csproj:
Lib.csproj:
and try to build the App project.
Expected behavior
A WebAssembly library should be able to reference another WebAssembly library in the same way as an ordinary .NET library.
To work without the library's generated WebAssembly runtime/application assets being treated as independent static web assets that conflict with the consuming application's own
_frameworkassets.The library needs to be able to provide its own intentional web assets (for example
.js), while its intermediate/generated WebAssembly files should not cause duplicate static-web-asset entries in the consuming application.Actual behavior
Build error.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response