-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[browser] Wasm SDK packed as a nuget package (#84082)
- Loading branch information
Showing
17 changed files
with
2,178 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/Microsoft.NET.Sdk.WebAssembly.Pack.pkgproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project DefaultTargets="Build"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" /> | ||
|
||
<PropertyGroup> | ||
<PackageDescription>SDK for building and publishing WebAssembly applications.</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoTasksDir)Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" /> | ||
<PackageFile Include="build\*.props;build\*.targets;build\*.web.config" TargetPath="build" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" /> | ||
</Project> |
43 changes: 43 additions & 0 deletions
43
...uget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.NET.Sdk.WebAssembly.props | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project ToolsVersion="14.0" TreatAsLocalProperty="RuntimeIdentifier"> | ||
<PropertyGroup> | ||
<!-- Avoid having the rid show up in output paths --> | ||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> | ||
|
||
<OutputType>exe</OutputType> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject> | ||
|
||
<!-- Turn off symbol publishing by default --> | ||
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory> | ||
|
||
<!-- Trimmer defaults --> | ||
<PublishTrimmed Condition="'$(PublishTrimmed)' == ''">true</PublishTrimmed> | ||
<TrimMode Condition="'$(TrimMode)' == ''">partial</TrimMode> | ||
<TrimmerRemoveSymbols Condition="'$(TrimmerRemoveSymbols)' == ''">false</TrimmerRemoveSymbols> | ||
|
||
<!-- Static web assets defaults --> | ||
<StaticWebAssetBasePath Condition="'$(StaticWebAssetBasePath)' == ''">/</StaticWebAssetBasePath> | ||
<StaticWebAssetProjectMode Condition="'$(StaticWebAssetProjectMode)' == ''">Root</StaticWebAssetProjectMode> | ||
<StaticWebAssetsAdditionalBuildPropertiesToRemove>$(StaticWebAssetsAdditionalBuildPropertiesToRemove);RuntimeIdentifier;SelfContained</StaticWebAssetsAdditionalBuildPropertiesToRemove> | ||
<StaticWebAssetsGetPublishAssetsTargets>ComputeFilesToPublish;GetCurrentProjectPublishStaticWebAssetItems</StaticWebAssetsGetPublishAssetsTargets> | ||
<StaticWebAssetsAdditionalPublishProperties>$(StaticWebAssetsAdditionalPublishProperties);BuildProjectReferences=false;ResolveAssemblyReferencesFindRelatedSatellites=true</StaticWebAssetsAdditionalPublishProperties> | ||
<StaticWebAssetsAdditionalPublishPropertiesToRemove>$(StaticWebAssetsAdditionalPublishPropertiesToRemove);NoBuild;RuntimeIdentifier</StaticWebAssetsAdditionalPublishPropertiesToRemove> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectCapability Include="WebAssembly" /> | ||
</ItemGroup> | ||
</Project> |
493 changes: 493 additions & 0 deletions
493
...et/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
Large diffs are not rendered by default.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
...o/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Pack.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.NET.Sdk.WebAssembly.props | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project ToolsVersion="14.0"> | ||
<PropertyGroup> | ||
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">browser-wasm</RuntimeIdentifier> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'"> | ||
<_WebAssemblyPropsFile>$(MSBuildThisFileDirectory)\Microsoft.NET.Sdk.WebAssembly.Browser.props</_WebAssemblyPropsFile> | ||
<_WebAssemblyTargetsFile>$(MSBuildThisFileDirectory)\Microsoft.NET.Sdk.WebAssembly.Browser.targets</_WebAssemblyTargetsFile> | ||
</PropertyGroup> | ||
</Project> |
12 changes: 12 additions & 0 deletions
12
...nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Pack.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.NET.Sdk.WebAssembly.targets | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project ToolsVersion="14.0"></Project> |
44 changes: 44 additions & 0 deletions
44
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Wasm.web.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<system.webServer> | ||
<staticContent> | ||
<remove fileExtension=".blat" /> | ||
<remove fileExtension=".dat" /> | ||
<remove fileExtension=".dll" /> | ||
<remove fileExtension=".webcil" /> | ||
<remove fileExtension=".json" /> | ||
<remove fileExtension=".wasm" /> | ||
<remove fileExtension=".woff" /> | ||
<remove fileExtension=".woff2" /> | ||
<mimeMap fileExtension=".blat" mimeType="application/octet-stream" /> | ||
<mimeMap fileExtension=".dll" mimeType="application/octet-stream" /> | ||
<mimeMap fileExtension=".webcil" mimeType="application/octet-stream" /> | ||
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" /> | ||
<mimeMap fileExtension=".json" mimeType="application/json" /> | ||
<mimeMap fileExtension=".wasm" mimeType="application/wasm" /> | ||
<mimeMap fileExtension=".woff" mimeType="application/font-woff" /> | ||
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" /> | ||
</staticContent> | ||
<httpCompression> | ||
<dynamicTypes> | ||
<add mimeType="application/octet-stream" enabled="true" /> | ||
<add mimeType="application/wasm" enabled="true" /> | ||
</dynamicTypes> | ||
</httpCompression> | ||
<rewrite> | ||
<rules> | ||
<rule name="Serve subdir"> | ||
<match url=".*" /> | ||
<action type="Rewrite" url="wwwroot\{R:0}" /> | ||
</rule> | ||
<rule name="SPA fallback routing" stopProcessing="true"> | ||
<match url=".*" /> | ||
<conditions logicalGrouping="MatchAll"> | ||
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> | ||
</conditions> | ||
<action type="Rewrite" url="wwwroot\" /> | ||
</rule> | ||
</rules> | ||
</rewrite> | ||
</system.webServer> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Microsoft.NET.Sdk.WebAssembly; | ||
|
||
public class AssetsComputingHelper | ||
{ | ||
public static bool ShouldFilterCandidate( | ||
ITaskItem candidate, | ||
bool timezoneSupport, | ||
bool invariantGlobalization, | ||
bool copySymbols, | ||
string customIcuCandidateFilename, | ||
out string reason) | ||
{ | ||
var extension = candidate.GetMetadata("Extension"); | ||
var fileName = candidate.GetMetadata("FileName"); | ||
var assetType = candidate.GetMetadata("AssetType"); | ||
var fromMonoPackage = string.Equals( | ||
candidate.GetMetadata("NuGetPackageId"), | ||
"Microsoft.NETCore.App.Runtime.Mono.browser-wasm", | ||
StringComparison.Ordinal); | ||
|
||
reason = extension switch | ||
{ | ||
".a" when fromMonoPackage => "extension is .a is not supported.", | ||
".c" when fromMonoPackage => "extension is .c is not supported.", | ||
".h" when fromMonoPackage => "extension is .h is not supported.", | ||
// It is safe to filter out all XML files since we are not interested in any XML file from the list | ||
// of ResolvedFilesToPublish to become a static web asset. Things like this include XML doc files and | ||
// so on. | ||
".xml" => "it is a documentation file", | ||
".rsp" when fromMonoPackage => "extension is .rsp is not supported.", | ||
".props" when fromMonoPackage => "extension is .props is not supported.", | ||
".blat" when !timezoneSupport => "timezone support is not enabled.", | ||
".dat" when invariantGlobalization && fileName.StartsWith("icudt") => "invariant globalization is enabled", | ||
".dat" when !string.IsNullOrEmpty(customIcuCandidateFilename) && fileName != customIcuCandidateFilename => "custom icu file will be used instead of icu from the runtime pack", | ||
".json" when fromMonoPackage && (fileName == "emcc-props" || fileName == "package") => $"{fileName}{extension} is not used by Blazor", | ||
".ts" when fromMonoPackage && fileName == "dotnet.d" => "dotnet type definition is not used by Blazor", | ||
".ts" when fromMonoPackage && fileName == "dotnet-legacy.d" => "dotnet type definition is not used by Blazor", | ||
".js" when assetType == "native" && fileName != "dotnet" => $"{fileName}{extension} is not used by Blazor", | ||
".pdb" when !copySymbols => "copying symbols is disabled", | ||
".symbols" when fromMonoPackage => "extension .symbols is not required.", | ||
_ => null | ||
}; | ||
|
||
return reason != null; | ||
} | ||
|
||
public static string GetCandidateRelativePath(ITaskItem candidate) | ||
{ | ||
var destinationSubPath = candidate.GetMetadata("DestinationSubPath"); | ||
if (!string.IsNullOrEmpty(destinationSubPath)) | ||
return $"_framework/{destinationSubPath}"; | ||
|
||
var relativePath = candidate.GetMetadata("FileName") + candidate.GetMetadata("Extension"); | ||
return $"_framework/{relativePath}"; | ||
} | ||
|
||
public static ITaskItem GetCustomIcuAsset(ITaskItem candidate) | ||
{ | ||
var customIcuCandidate = new TaskItem(candidate); | ||
var relativePath = GetCandidateRelativePath(customIcuCandidate); | ||
customIcuCandidate.SetMetadata("RelativePath", relativePath); | ||
customIcuCandidate.SetMetadata("AssetTraitName", "BlazorWebAssemblyResource"); | ||
customIcuCandidate.SetMetadata("AssetTraitValue", "native"); | ||
customIcuCandidate.SetMetadata("AssetType", "native"); | ||
return customIcuCandidate; | ||
} | ||
|
||
public static bool TryGetAssetFilename(ITaskItem candidate, out string filename) | ||
{ | ||
bool candidateIsValid = candidate != null && !string.IsNullOrEmpty(candidate.ItemSpec); | ||
filename = candidateIsValid ? | ||
$"{candidate.GetMetadata("FileName")}" : | ||
""; | ||
return candidateIsValid; | ||
} | ||
} |
Oops, something went wrong.