未验证 提交 6631b478 编写于 作者: A Ankit Jain 提交者: GitHub

[wasm] Fix analyzer support in templates (#77704)

- Add
  `[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")]`
  to the browser, and console templates. This would allow the analyzers,
  if enabled, to treat the assembly as one that will run only on
  browser.

- Populate `@(SupportedPlatform)` with only `browser`, for *wasm*
  projects, similar to https://github.com/dotnet/sdk/blob/fef8cedfb6b4ac85a7e135f3e4f155e29cdcbdf1/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.5_0.targets#L75-L79

- This also fixes the firefox CI build which regressed recently
上级 7ba371c7
...@@ -38,14 +38,12 @@ ...@@ -38,14 +38,12 @@
</PrepareForBuildHelixWorkItems_WasmDependsOn> </PrepareForBuildHelixWorkItems_WasmDependsOn>
<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);StageEmSdkForHelix;PrepareForBuildHelixWorkItems_Wasm</BuildHelixWorkItemsDependsOn> <BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);StageEmSdkForHelix;PrepareForBuildHelixWorkItems_Wasm</BuildHelixWorkItemsDependsOn>
<BuildHelixWorkItemsDependsOn Condition="'$(WindowsShell)' != 'true'">$(BuildHelixWorkItemsDependsOn);DownloadFirefoxToSendToHelix</BuildHelixWorkItemsDependsOn>
<IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload> <IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload>
<EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems> <EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems>
<!-- on unix CI has emscripten provisioned in $(EMSDK_PATH) as `/usr/local/emscripten`. --> <!-- on unix CI has emscripten provisioned in $(EMSDK_PATH) as `/usr/local/emscripten`. -->
<EMSDK_PATH Condition="$([MSBuild]::IsOSPlatform('WINDOWS')) and '$(EMSDK_PATH)' == ''">$(RepoRoot)src\mono\wasm\emsdk\</EMSDK_PATH> <EMSDK_PATH Condition="$([MSBuild]::IsOSPlatform('WINDOWS')) and '$(EMSDK_PATH)' == ''">$(RepoRoot)src\mono\wasm\emsdk\</EMSDK_PATH>
<EmSdkDirForHelixPayload>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'emsdk'))</EmSdkDirForHelixPayload> <EmSdkDirForHelixPayload>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'emsdk'))</EmSdkDirForHelixPayload>
<FirefoxForHelixPayload>$(TestArchiveRoot)firefox.zip</FirefoxForHelixPayload>
<DebuggerHost Condition="'$(DebuggerHost)' == ''">chrome</DebuggerHost> <DebuggerHost Condition="'$(DebuggerHost)' == ''">chrome</DebuggerHost>
<NeedsWorkload Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsWorkload> <NeedsWorkload Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsWorkload>
...@@ -159,17 +157,18 @@ ...@@ -159,17 +157,18 @@
<Target Name="PrepareHelixCorrelationPayload_Wasm"> <Target Name="PrepareHelixCorrelationPayload_Wasm">
<Message Condition="'$(NeedsEMSDK)' == 'true' or '$(NeedsEMSDKNode)' == 'true'" Importance="High" Text="Using emsdk: $(EmSdkDirForHelixPayload)" /> <Message Condition="'$(NeedsEMSDK)' == 'true' or '$(NeedsEMSDKNode)' == 'true'" Importance="High" Text="Using emsdk: $(EmSdkDirForHelixPayload)" />
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and !Exists($(ChromeDir))" <Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'chrome' and !Exists($(ChromeDir))"
Text="Could not find chrome at $(ChromeDir)" /> Text="Could not find chrome at $(ChromeDir)" />
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and !Exists($(ChromeDriverDir))" <Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'chrome' and !Exists($(ChromeDriverDir))"
Text="Could not find chromedriver at $(ChromeDriverDir)" /> Text="Could not find chromedriver at $(ChromeDriverDir)" />
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'firefox' and !Exists($(FirefoxDir))"
Text="Could not find firefox at $(FirefoxDir)" />
<ItemGroup Condition="'$(NeedsToRunOnBrowser)' == 'true'"> <ItemGroup Condition="'$(NeedsToRunOnBrowser)' == 'true'">
<HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDir)" /> <HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDir)" />
<HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDriverDir)" /> <HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDriverDir)" />
<!--<HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="firefox" Uri="$(FirefoxUrl)" />--> <HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="$(FirefoxDir)" />
<HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="$(FirefoxForHelixPayload)" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(NeedsEMSDK)' == 'true'"> <ItemGroup Condition="'$(NeedsEMSDK)' == 'true'">
...@@ -291,11 +290,4 @@ ...@@ -291,11 +290,4 @@
DestinationFiles="@(_EmSdkFiles -> '$(EmSdkDirForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')" DestinationFiles="@(_EmSdkFiles -> '$(EmSdkDirForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')"
SkipUnchangedFiles="true" /> SkipUnchangedFiles="true" />
</Target> </Target>
<Target Name="DownloadFirefoxToSendToHelix" Condition="!Exists($(FirefoxForHelixPayload)) and '$(DebuggerHost)' == 'firefox'">
<DownloadFile SourceUrl="$(FirefoxUrl)" DestinationFolder="$(TestArchiveRoot)" SkipUnchangedFiles="true">
<Output TaskParameter="DownloadedFile" PropertyName="_DownloadedFile" />
</DownloadFile>
<Exec Command="tar -xf $(_DownloadedFile) -C $(TestArchiveRoot) &amp;&amp; rm $(_DownloadedFile) &amp;&amp; cd $(TestArchiveRoot) &amp;&amp; zip -q -r firefox.zip firefox"/>
</Target>
</Project> </Project>
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
HelixTargetQueues=$(HelixTargetQueues); HelixTargetQueues=$(HelixTargetQueues);
BuildTargetFramework=$(BuildTargetFramework) BuildTargetFramework=$(BuildTargetFramework)
</_PropertiesToPass> </_PropertiesToPass>
<_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">$(DebuggerHost)</_DebuggerHosts>
<_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">chrome</_DebuggerHosts> <_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">chrome</_DebuggerHosts>
</PropertyGroup> </PropertyGroup>
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")]
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)CommonAssemblyInfo.cs" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
......
...@@ -463,7 +463,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s ...@@ -463,7 +463,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s
return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{localNuGetsPath}"" />"); return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{localNuGetsPath}"" />");
} }
public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "") public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "", bool runAnalyzers = true)
{ {
InitPaths(id); InitPaths(id);
InitProjectDir(_projectDir, addNuGetSourceForLocalPackages: true); InitProjectDir(_projectDir, addNuGetSourceForLocalPackages: true);
...@@ -483,7 +483,10 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse ...@@ -483,7 +483,10 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
.ExecuteWithCapturedOutput($"new {template} {extraArgs}") .ExecuteWithCapturedOutput($"new {template} {extraArgs}")
.EnsureSuccessful(); .EnsureSuccessful();
return Path.Combine(_projectDir!, $"{id}.csproj"); string projectfile = Path.Combine(_projectDir!, $"{id}.csproj");
if (runAnalyzers)
AddItemsPropertiesToProject("<RunAnalyzers>true</RunAnalyzers>");
return projectfile;
} }
public string CreateBlazorWasmTemplateProject(string id) public string CreateBlazorWasmTemplateProject(string id)
......
...@@ -120,6 +120,9 @@ ...@@ -120,6 +120,9 @@
<ItemGroup> <ItemGroup>
<!-- Allow running/debugging from VS --> <!-- Allow running/debugging from VS -->
<ProjectCapability Include="DotNetCoreWeb"/> <ProjectCapability Include="DotNetCoreWeb"/>
<SupportedPlatform Condition="'$(IsWasmProject)' == 'true'" Remove="@(SupportedPlatform)" />
<SupportedPlatform Condition="'$(IsWasmProject)' == 'true'" Include="browser" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Identify app bundle directory to run from"> <PropertyGroup Label="Identify app bundle directory to run from">
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
<DebuggerHost Condition="'$(DebuggerHost)' == '' or ('$(DebuggerHost)' != 'chrome' and '$(DebuggerHost)' != 'firefox')">chrome</DebuggerHost> <DebuggerHost Condition="'$(DebuggerHost)' == '' or ('$(DebuggerHost)' != 'chrome' and '$(DebuggerHost)' != 'firefox')">chrome</DebuggerHost>
<DefineConstants Condition="'$(DebuggerHost)' == 'chrome'">$(DefineConstants);RUN_IN_CHROME</DefineConstants> <DefineConstants Condition="'$(DebuggerHost)' == 'chrome'">$(DefineConstants);RUN_IN_CHROME</DefineConstants>
<BrowserHost Condition="$([MSBuild]::IsOSPlatform('windows'))">windows</BrowserHost> <BrowserHost Condition="$([MSBuild]::IsOSPlatform('windows'))">windows</BrowserHost>
<InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and '$(DebuggerHost)' == 'chrome' and ('$(ContinuousIntegrationBuild)' == 'true' or Exists('/.dockerenv'))">true</InstallChromeForTests> <_ProvisionBrowser Condition="'$(ContinuousIntegrationBuild)' == 'true' or Exists('/.dockerenv')">true</_ProvisionBrowser>
<InstallFirefoxForTests Condition="'$(DebuggerHost)' == 'firefox' and '$(InstallFirefoxForTests)' == '' and '$(ContinuousIntegrationBuild)' != 'true' and Exists('/.dockerenv')">true</InstallFirefoxForTests> <InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and '$(DebuggerHost)' == 'chrome' and '$(_ProvisionBrowser)' == 'true'">true</InstallChromeForTests>
<InstallFirefoxForTests Condition="'$(InstallFirefoxForTests)' == '' and '$(DebuggerHost)' == 'firefox' and '$(_ProvisionBrowser)' == 'true'">true</InstallFirefoxForTests>
<!-- Set RunSettingsFilePath property which is read by VSTest. --> <!-- Set RunSettingsFilePath property which is read by VSTest. -->
<RunSettingsFilePath Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(OutputPath).runsettings</RunSettingsFilePath> <RunSettingsFilePath Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(OutputPath).runsettings</RunSettingsFilePath>
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
ArchiveDirForHelix=$(TargetDir); ArchiveDirForHelix=$(TargetDir);
TestArchiveTestsDir=$(TestArchiveTestsDir); TestArchiveTestsDir=$(TestArchiveTestsDir);
ExtractTestClassNamesForHelix=$(ExtractTestClassNamesForHelix); ExtractTestClassNamesForHelix=$(ExtractTestClassNamesForHelix);
DebuggerHost=$(DebuggerHost);
DotNetForTests=$([MSBuild]::NormalizePath($(DotNetRoot), $(DotNetTool)))" /> DotNetForTests=$([MSBuild]::NormalizePath($(DotNetRoot), $(DotNetTool)))" />
</ItemGroup> </ItemGroup>
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")]
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册