Use properties for target versions for core and framework (#67717)
authorLarry Ewing <lewing@microsoft.com>
Fri, 8 Apr 2022 19:54:58 +0000 (14:54 -0500)
committerGitHub <noreply@github.com>
Fri, 8 Apr 2022 19:54:58 +0000 (14:54 -0500)
* Populate target framework versions for tasks, and generated nugets based

.. on other properties, instead of hardcoding the values.

* Version substitution for MonoTargets nuget

* Version substitution for MonoAOTCompiler nuget

* sendhelixhelp.proj: Ensure that DotNetCliVersion gets overridden, as

.. intended. This seems to have been broken by the condition being
removed in
https://github.com/dotnet/arcade/commit/cfdac3560f1c887780bac171df7c22f7805e6f40
from the `DotNetCliVersion` property, causing the value to always
overridden again to `6.0.100`.

And this breaks wasm aot/eat tests on helix:
```
/datadisks/disk1/work/A4EE08D9/p/build/wasm/WasmApp.Native.targets(569,5): error MSB4062: The "MonoAOTCompiler" task could not be loaded from the assembly /datadisks/disk1/work/A4EE08D9/p/build/MonoAOTCompiler/MonoAOTCompiler.dll. Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. [/datadisks/disk1/work/A4EE08D9/w/B3AE0955/e/publish/ProxyProjectForAOTOnHelix.proj]
/datadisks/disk1/work/A4EE08D9/p/build/wasm/WasmApp.Native.targets(569,5): error MSB4062:  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
```

* Fix build for net7.0

Fails with:
```
src/tests/tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcSocket.cs(27,35): error CS0108: 'IpcSocket.AcceptAsync(CancellationToken)' hides inherited member 'Socket.AcceptAsync(CancellationToken)'. Use the new keyword if hiding was intended. [/__w/1/s/src/tests/tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj]
```

* Fix some more target frameworks

* bump the workload sdk version

* Revert "sendhelixhelp.proj: Ensure that DotNetCliVersion gets overridden, as"

This reverts commit 426b4b19155d54a7f338140f4c87feec471b5d92.

Last update to Arcade's XHarnessRunner.targets unconditionally set
DotNetCliVersion, to workaround which this commit was added. But the
update in this PR changed DotNetCliPackageType to `aspnetcore-runtime`,
which makes the version from global.json - `6.0.100` incorrect for
aspnetcore.

And the next upcoming update will set versions explicitly and change the
DotNetCliPackageType back to `sdk`.

Instead, revert this. And don't use version from global.json for now,
instead relying on the version that xharnesrunner.targets sets.

Co-authored-by: Ankit Jain <radical@gmail.com>
13 files changed:
Directory.Build.props
src/libraries/sendtohelix-wasm.targets
src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj
src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props [deleted file]
src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props.in [new file with mode: 0644]
src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj
src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/MonoTargetsTasks.props.in [moved from src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/MonoTargetsTasks.props with 81% similarity]
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets.in [moved from src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets with 76% similarity]
src/mono/wasm/build/WasmApp.InTree.props
src/mono/wasm/templates/Microsoft.NET.Runtime.WebAssembly.Templates.csproj
src/tasks/Directory.Build.props [deleted file]
src/tests/tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcSocket.cs

index ea12ca7..2ec01ea 100644 (file)
     <NetFrameworkToolCurrent>net472</NetFrameworkToolCurrent>
     <!-- Don't build for NETFramework during source-build. -->
     <NetFrameworkToolCurrent Condition="'$(DotNetBuildFromSource)' == 'true'" />
+
+    <TargetFrameworkForNETFrameworkTasks>$(NetFrameworkToolCurrent)</TargetFrameworkForNETFrameworkTasks>
+    <!-- Don't build for NETFramework during source-build. -->
+    <TargetFrameworkForNETFrameworkTasks Condition="'$(DotNetBuildFromSource)' == 'true'" />
+
+    <TargetFrameworkForNETCoreTasks>$(NetCoreAppToolCurrent)</TargetFrameworkForNETCoreTasks>
   </PropertyGroup>
 
   <PropertyGroup>
index f376529..cdd77a6 100644 (file)
@@ -97,7 +97,7 @@
     <When Condition="'$(NeedsEMSDK)' == 'true'">
       <PropertyGroup>
         <NeedsDotNetSdk>true</NeedsDotNetSdk>
-        <UseDotNetCliVersionFromGlobalJson>true</UseDotNetCliVersionFromGlobalJson>
+        <!--<UseDotNetCliVersionFromGlobalJson>true</UseDotNetCliVersionFromGlobalJson>-->
         <IncludeXHarnessCli>true</IncludeXHarnessCli>
         <EnableXHarnessTelemetry>false</EnableXHarnessTelemetry>
       </PropertyGroup>
index 1cf00b6..e5a5b52 100644 (file)
@@ -8,9 +8,28 @@
   <ItemGroup>
     <ProjectReference Include="$(RepoTasksDir)AotCompilerTask\MonoAOTCompiler.csproj" />
 
-    <PackageFile Include="Sdk\Sdk.props" TargetPath="Sdk" />
     <PackageFile Include="build\$(MSBuildProjectName).props" TargetPath="build" />
   </ItemGroup>
 
+  <Target Name="_PrepareForPack" BeforeTargets="GetPackageFiles">
+    <PropertyGroup>
+      <SdkPropsPath>$(IntermediateOutputPath)Sdk.props</SdkPropsPath>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <_ReplacementValue Include="TargetFrameworkForNETCoreTasks" Value="$(TargetFrameworkForNETCoreTasks)" />
+      <_ReplacementValue Include="TargetFrameworkForNETFrameworkTasks" Value="$(TargetFrameworkForNETFrameworkTasks)" />
+    </ItemGroup>
+
+    <GenerateFileFromTemplate
+      TemplateFile="Sdk/Sdk.props.in"
+      Properties="@(_ReplacementValue)"
+      OutputPath="$(SdkPropsPath)" />
+
+    <ItemGroup>
+      <PackageFile Include="$(SdkPropsPath)" TargetPath="Sdk" />
+    </ItemGroup>
+  </Target>
+
   <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
 </Project>
diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props b/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props
deleted file mode 100644 (file)
index a94224b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<Project>
-  <PropertyGroup>
-    <MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\net6.0\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
-    <MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\net472\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
-  </PropertyGroup>
-  <UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />
-</Project>
diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props.in b/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Sdk/Sdk.props.in
new file mode 100644 (file)
index 0000000..bc14a61
--- /dev/null
@@ -0,0 +1,7 @@
+<Project>
+  <PropertyGroup>
+    <MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
+    <MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
+  </PropertyGroup>
+  <UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />
+</Project>
index a38b1d3..8d9e3de 100644 (file)
     <PackageFile Include="Sdk\Sdk.props" TargetPath="Sdk" />
     <PackageFile Include="Sdk\Sdk.targets" TargetPath="Sdk" />
     <PackageFile Include="build\$(MSBuildProjectName).props" TargetPath="build" />
-    <PackageFile Include="Sdk\MonoTargetsTasks.props" TargetPath="Sdk" />
     <PackageFile Include="Sdk\RuntimeComponentManifest.targets" TargetPath="Sdk" />
   </ItemGroup>
 
+  <Target Name="_PrepareForPack" BeforeTargets="GetPackageFiles">
+    <PropertyGroup>
+      <MonoTargetsTasksPropsPath>$(IntermediateOutputPath)MonoTargetsTasks.props</MonoTargetsTasksPropsPath>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <_ReplacementValue Include="TargetFrameworkForNETCoreTasks" Value="$(TargetFrameworkForNETCoreTasks)" />
+      <_ReplacementValue Include="TargetFrameworkForNETFrameworkTasks" Value="$(TargetFrameworkForNETFrameworkTasks)" />
+    </ItemGroup>
+
+    <GenerateFileFromTemplate
+      TemplateFile="Sdk/MonoTargetsTasks.props.in"
+      Properties="@(_ReplacementValue)"
+      OutputPath="$(MonoTargetsTasksPropsPath)" />
+
+    <ItemGroup>
+      <PackageFile Include="$(MonoTargetsTasksPropsPath)" TargetPath="Sdk" />
+    </ItemGroup>
+  </Target>
+
   <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
 </Project>
@@ -1,7 +1,7 @@
 <Project>
   <PropertyGroup>
-    <MonoTargetsTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\net6.0\MonoTargetsTasks.dll</MonoTargetsTasksAssemblyPath>
-    <MonoTargetsTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\net472\MonoTargetsTasks.dll</MonoTargetsTasksAssemblyPath>
+    <MonoTargetsTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\MonoTargetsTasks.dll</MonoTargetsTasksAssemblyPath>
+    <MonoTargetsTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\MonoTargetsTasks.dll</MonoTargetsTasksAssemblyPath>
   </PropertyGroup>
   <!-- ILStrip -->
   <UsingTask TaskName="ILStrip" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
index 874775f..3116e99 100644 (file)
@@ -9,7 +9,6 @@
     <ProjectReference Include="$(RepoTasksDir)WasmAppBuilder\WasmAppBuilder.csproj" />
     <ProjectReference Include="$(RepoTasksDir)WasmBuildTasks\WasmBuildTasks.csproj" />
 
-    <PackageFile Include="Sdk\Sdk.targets" TargetPath="Sdk" />
     <PackageFile Include="Sdk\AutoImport.props" TargetPath="Sdk" />
     <PackageFile Include="$(RepoRoot)\src\mono\wasm\build\WasmApp.props" TargetPath="Sdk" />
     <PackageFile Include="$(RepoRoot)\src\mono\wasm\build\WasmApp.targets" TargetPath="Sdk" />
     <PackageFile Include="$(RepoRoot)\src\mono\wasm\build\EmSdkRepo.Defaults.props" TargetPath="Sdk" />
   </ItemGroup>
 
+  <Target Name="_PrepareForPack" BeforeTargets="GetPackageFiles">
+    <PropertyGroup>
+      <SdkTargetsPath>$(IntermediateOutputPath)Sdk.targets</SdkTargetsPath>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <_ReplacementValue Include="TargetFrameworkForNETCoreTasks" Value="$(TargetFrameworkForNETCoreTasks)" />
+      <_ReplacementValue Include="TargetFrameworkForNETFrameworkTasks" Value="$(TargetFrameworkForNETFrameworkTasks)" />
+    </ItemGroup>
+
+    <GenerateFileFromTemplate
+      TemplateFile="Sdk/Sdk.targets.in"
+      Properties="@(_ReplacementValue)"
+      OutputPath="$(SdkTargetsPath)" />
+
+    <ItemGroup>
+      <PackageFile Include="$(SdkTargetsPath)" TargetPath="Sdk" />
+    </ItemGroup>
+  </Target>
+
   <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
 </Project>
@@ -1,8 +1,8 @@
 <Project>
   <!-- Property overrides -->
   <PropertyGroup>
-    <_TasksDir Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\net6.0\</_TasksDir>
-    <_TasksDir Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\net472\</_TasksDir>
+    <_TasksDir Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\</_TasksDir>
+    <_TasksDir Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\</_TasksDir>
 
     <WasmAppBuilderTasksAssemblyPath>$(_TasksDir)WasmAppBuilder.dll</WasmAppBuilderTasksAssemblyPath>
     <WasmBuildTasksAssemblyPath>$(_TasksDir)WasmBuildTasks.dll</WasmBuildTasksAssemblyPath>
index ab70ccd..7f65576 100644 (file)
@@ -5,7 +5,7 @@
   <PropertyGroup>
     <Platform>AnyCPU</Platform>
     <EnableTargetingPackDownload>false</EnableTargetingPackDownload>
-    <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
+    <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
     <EMSDK_PATH Condition="'$(EMSDK_PATH)' == '' and '$(MonoProjectRoot)' != ''">$([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasm', 'emsdk'))</EMSDK_PATH>
     <RunAOTCompilation Condition="'$(RunAOTCompilation)' == ''">false</RunAOTCompilation>
     <PublishTrimmed>true</PublishTrimmed>
index 77f730d..dfe18d9 100644 (file)
@@ -8,7 +8,7 @@
     <Description>Templates to create WebAssembly projects.</Description>
     <PackageTags>dotnet-new;templates</PackageTags>
 
-    <TargetFramework>net6.0</TargetFramework>
+    <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
 
     <IncludeContentInPack>true</IncludeContentInPack>
     <IncludeBuildOutput>false</IncludeBuildOutput>
diff --git a/src/tasks/Directory.Build.props b/src/tasks/Directory.Build.props
deleted file mode 100644 (file)
index 887be3a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<Project>
-  <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, '$(MSBuildThisFileDirectory)..'))" />
-
-  <PropertyGroup>
-    <TargetFrameworkForNETFrameworkTasks>net472</TargetFrameworkForNETFrameworkTasks>
-    <!-- Don't build for NETFramework during source-build. -->
-    <TargetFrameworkForNETFrameworkTasks Condition="'$(DotNetBuildFromSource)' == 'true'" />
-
-    <TargetFrameworkForNETCoreTasks>net6.0</TargetFrameworkForNETCoreTasks>
-  </PropertyGroup>
-</Project>
index 27b0b07..921ebc2 100644 (file)
@@ -23,7 +23,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
         }
 
 // .NET 6 implements this method directly on Socket, but for earlier runtimes we need a polyfill
-#if !NET6_0
+#if !NET6_0_OR_GREATER
         public async Task<Socket> AcceptAsync(CancellationToken token)
         {
             using (token.Register(() => Close(0)))
@@ -63,7 +63,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
         }
 
 // .NET 6 implements this method directly on Socket, but for earlier runtimes we need a polyfill
-#if !NET6_0
+#if !NET6_0_OR_GREATER
         public async Task ConnectAsync(EndPoint remoteEP, CancellationToken token)
         {
             using (token.Register(() => Close(0)))