Skip to content

Further centralize shared Fx and TFM transition workarounds #27473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 3, 2020
Prev Previous commit
Next Next commit
Use generated Directory.Build.* files for local template tests
- move Infrastructure/ files to TestInfrastructure/
  - Infrastructure/ sub-directories were functionally identical
- move shared parts of template test project files to PrepareForTest.targets
  • Loading branch information
dougbu committed Dec 3, 2020
commit 66198208749efdfbb84843cbb2df446e9fd9656d
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<!-- TestTemplateCreationFolder is the folder where the templates will be created. Will point out to $(OutputDir)$(TestTemplateCreationFolder) -->
<TestTemplateCreationFolder>TestTemplates\</TestTemplateCreationFolder>
<TestPackageRestorePath>$([MSBuild]::EnsureTrailingSlash('$(RepoRoot)'))obj\template-restore\</TestPackageRestorePath>
<TestTemplateTestsProps>TemplateTests.props</TestTemplateTestsProps>
<TestDependsOnAspNetRuntime>true</TestDependsOnAspNetRuntime>
</PropertyGroup>

Expand All @@ -42,105 +41,7 @@
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>DotNetEfFullPath</_Parameter1>
<_Parameter2>$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))dotnet-ef/$(DotnetEfVersion)/tools/netcoreapp3.1/any/dotnet-ef.dll</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestPackageRestorePath</_Parameter1>
<_Parameter2>$(TestPackageRestorePath)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Test.DefaultTargetFramework</_Parameter1>
<_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<_Parameter1>ContinuousIntegrationBuild</_Parameter1>
<_Parameter2>true</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
<PropertyGroup>
<TestTemplateCreationFolder>$([MSBuild]::NormalizePath('$(OutputPath)$(TestTemplateCreationFolder)'))</TestTemplateCreationFolder>
<TestTemplateTestsProps>$(TestTemplateCreationFolder)$(TestTemplateTestsProps)</TestTemplateTestsProps>
<CustomTemplateHivePath>$(TestTemplateCreationFolder)\Hives\$([System.Guid]::NewGuid())\.templateengine</CustomTemplateHivePath>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsShippingPackagesDir</_Parameter1>
<_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsLogDir</_Parameter1>
<_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
<_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestTemplateCreationFolder</_Parameter1>
<_Parameter2>$(TestTemplateCreationFolder)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>CustomTemplateHivePath</_Parameter1>
<_Parameter2>$(CustomTemplateHivePath)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<Message Importance="high" Text="Preparing environment for tests" />
<!-- Remove the template creation folders and the package-restore folders to ensure that when we run the tests we don't
get cached results and changes show up.
-->

<ItemGroup>
<_ExistingFilesFromLastRun Include="$(TestTemplateCreationFolder)**\*" />
</ItemGroup>

<Delete Files="@(_ExistingFilesFromLastRun)" ContinueOnError="true" />

<Removedir Directories="$(TestTemplateCreationFolder)" Condition="Exists('$(TestTemplateCreationFolder)')" ContinueOnError="true">
<Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
</Removedir>
<Removedir Directories="$(TestPackageRestorePath)" Condition="Exists('$(TestPackageRestorePath)')" ContinueOnError="true">
<Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
</Removedir>

<Message Importance="high" Text="Removed directory %(_CleanedUpDirectories.Identity)" />

<MakeDir Directories="$(TestTemplateCreationFolder)">
<Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
</MakeDir>
<MakeDir Directories="$(TestPackageRestorePath)">
<Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
</MakeDir>

<Message Importance="high" Text="Created directory %(_CreatedDirectories.Identity)" />

<GenerateFileFromTemplate
TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.targets.in"
Properties="TemplateTestsPropsPath=$(TestTemplateTestsProps)"
OutputPath="$(TestTemplateCreationFolder)Directory.Build.targets" />

<GenerateFileFromTemplate
TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.props.in"
Properties="RepoRoot=$(RepoRoot);DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework)"
OutputPath="$(TestTemplateCreationFolder)Directory.Build.props" />

<!-- Workaround https://github.com/dotnet/core-setup/issues/6420 - there is no MSBuild setting for rollforward yet -->
<Copy SourceFiles="$(MSBuildThisFileDirectory)Infrastructure\runtimeconfig.norollforward.json" DestinationFolder="$(TestTemplateCreationFolder)" UseHardLinksIfPossible="true" />

<Delete Files="$(TestTemplateTestsProps)" />

</Target>

<!-- Shared testing infrastructure for running E2E tests using selenium -->
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.targets" />

<Import Project="..\TestInfrastructure\PrepareForTest.targets" />
</Project>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions src/ProjectTemplates/TestInfrastructure/Directory.Build.props.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<!-- This file gets copied above the template test projects so that we disconnect the templates from the rest of the repository. -->
<PropertyGroup>
<RepoRoot>${RepoRoot}</RepoRoot>
<ArtifactsBinDir>${ArtifactsBinDir}</ArtifactsBinDir>
</PropertyGroup>

<Import Project="${ArtifactsBinDir}GenerateFiles\Directory.Build.props" />

<Import Project="${RepoRoot}src\Components\WebAssembly\Sdk\src\build\$(DefaultNetCoreTargetFramework)\Microsoft.NET.Sdk.BlazorWebAssembly.props"
Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'" />
</Project>
22 changes: 22 additions & 0 deletions src/ProjectTemplates/TestInfrastructure/Directory.Build.targets.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project>
<Import Project="$(ArtifactsBinDir)GenerateFiles\Directory.Build.targets" />

<PropertyGroup>
<RestoreAdditionalProjectSources>${RestoreAdditionalProjectSources}</RestoreAdditionalProjectSources>
<!-- This sets an option which prevents the tests from rolling forward into a newer shared framework. -->
<UserRuntimeConfig>$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
</PropertyGroup>

<!--
The version of the .NET Core SDK we build with often contains a version of the Razor SDK several versions older
than latest. We reference the project (see CSharp.Common.props) to ensure it's built before projects that use it.
Since this is a project reference, we must explicitly import the props file and also specify the output location
of the SDK directory.
-->
<PropertyGroup>
<RazorSdkDirectoryRoot>$(ArtifactsBinDir)Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
<BlazorWebAssemblySdkDirectoryRoot>$(ArtifactsBinDir)Microsoft.NET.Sdk.BlazorWebAssembly\${Configuration}\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
</PropertyGroup>
<Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props"
Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
</Project>
98 changes: 98 additions & 0 deletions src/ProjectTemplates/TestInfrastructure/PrepareForTest.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<Project>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>DotNetEfFullPath</_Parameter1>
<_Parameter2>$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))dotnet-ef/$(DotnetEfVersion)/tools/netcoreapp3.1/any/dotnet-ef.dll</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestPackageRestorePath</_Parameter1>
<_Parameter2>$(TestPackageRestorePath)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Test.DefaultTargetFramework</_Parameter1>
<_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<_Parameter1>ContinuousIntegrationBuild</_Parameter1>
<_Parameter2>true</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
<PropertyGroup>
<TestTemplateCreationFolder>$([MSBuild]::NormalizePath('$(OutputPath)$(TestTemplateCreationFolder)'))</TestTemplateCreationFolder>
<CustomTemplateHivePath>$(TestTemplateCreationFolder)\Hives\$([System.Guid]::NewGuid())\.templateengine</CustomTemplateHivePath>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsShippingPackagesDir</_Parameter1>
<_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsLogDir</_Parameter1>
<_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
<_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestTemplateCreationFolder</_Parameter1>
<_Parameter2>$(TestTemplateCreationFolder)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>CustomTemplateHivePath</_Parameter1>
<_Parameter2>$(CustomTemplateHivePath)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<Message Importance="high" Text="Preparing environment for tests" />
<!-- Remove the template creation folders and the package-restore folders to ensure that when we run the tests we don't
get cached results and changes show up.
-->

<ItemGroup>
<_ExistingFilesFromLastRun Include="$(TestTemplateCreationFolder)**\*" />
</ItemGroup>

<Delete Files="@(_ExistingFilesFromLastRun)" ContinueOnError="true" />

<Removedir Directories="$(TestTemplateCreationFolder)" Condition="Exists('$(TestTemplateCreationFolder)')" ContinueOnError="true">
<Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
</Removedir>
<Removedir Directories="$(TestPackageRestorePath)" Condition="Exists('$(TestPackageRestorePath)')" ContinueOnError="true">
<Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
</Removedir>

<Message Importance="high" Text="Removed directory %(_CleanedUpDirectories.Identity)" />

<MakeDir Directories="$(TestTemplateCreationFolder)">
<Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
</MakeDir>
<MakeDir Directories="$(TestPackageRestorePath)">
<Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
</MakeDir>

<Message Importance="high" Text="Created directory %(_CreatedDirectories.Identity)" />

<GenerateFileFromTemplate
TemplateFile="$(MSBuildThisFileDirectory)..\TestInfrastructure\Directory.Build.targets.in"
Properties="Configuration=$(Configuration);
RestoreAdditionalProjectSources=$([MSBuild]::Escape('$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir);$(ArtifactsNonShippingPackagesDir)'))"
OutputPath="$(TestTemplateCreationFolder)Directory.Build.targets" />

<GenerateFileFromTemplate
TemplateFile="$(MSBuildThisFileDirectory)..\TestInfrastructure\Directory.Build.props.in"
Properties="RepoRoot=$(RepoRoot);ArtifactsBinDir=$(ArtifactsBinDir)"
OutputPath="$(TestTemplateCreationFolder)Directory.Build.props" />

<!-- Workaround https://github.com/dotnet/core-setup/issues/6420 - there is no MSBuild setting for rollforward yet -->
<Copy SourceFiles="$(MSBuildThisFileDirectory)..\TestInfrastructure\runtimeconfig.norollforward.json"
DestinationFolder="$(TestTemplateCreationFolder)"
UseHardLinksIfPossible="true" />
</Target>
</Project>
4 changes: 0 additions & 4 deletions src/ProjectTemplates/test/Directory.Build.targets

This file was deleted.

This file was deleted.

This file was deleted.

Loading