Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit eddc1a6

Browse files
authored
Sdk test projects (#19044)
Change the associated targets and props files in the test directory to allow the test csproj's to be built as SDK style projects alongside traditional style projects. Remove CodeTaskFactory: - Allows the projects to be built using the core version of msbuild/dotnet build - Converted to using msbuild property expansion instead Add directory.build.{props,targets}: - Currently we just import the dirs.props and targets, but means SDK style projects don't need to explicitly include these files - We probably want to move all projects over to using these in the future, but this keeps the changes smaller for now Specific code for SDK projects: - There are a several changes required to build an SDK project. This change guards them behind conditionals so that only the new style projects see them. When we get to the point that there are only new projects, we can remove the guards (probably at the same time as ditching the dir.props) Reordered build targets: - Because SDK projects implicitly import the build targets, we can no longer re-define the build targets unconditionally knowing they will likely be overwritten. - Instead we move the overwritten targets to separate files, and include these conditionally based on properties. In this way there is always a build defined for SDK projects, which can then be overwritten to do nothing as needed.
1 parent 2b92e13 commit eddc1a6

15 files changed

+84
-62
lines changed

build-test.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
440440
set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
441441

442442
REM Build wrappers using the local SDK's msbuild. As we move to arcade, the other builds should be moved away from run.exe as well.
443-
call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /p:BuildWrappers=true !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__unprocessedBuildArgs%
443+
call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/ /p:BuildWrappers=true !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__unprocessedBuildArgs%
444444
if errorlevel 1 (
445445
echo Xunit Wrapper build failed
446446
exit /b 1

tests/dir.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<OsEnvironment Condition="'$(OsEnvironment)'==''">$(OS)</OsEnvironment>
99
</PropertyGroup>
1010

11+
<Import Project="dir.sdkbuild.props" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" />
12+
1113
<!-- Build Tools Versions -->
1214
<PropertyGroup>
1315
<RoslynVersion>1.0.0-rc3-20150510-01</RoslynVersion>

tests/dir.sdkbuild.props

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
and buildtools projects should go in dir.common.props. -->
77

88
<PropertyGroup>
9-
<TargetFramework>netcoreapp2.0</TargetFramework>
9+
<TargetFramework>netcoreapp3.0</TargetFramework>
10+
<RuntimeFrameworkVersion>$(MicrosoftNETCoreRuntimeCoreCLRPackageVersion)</RuntimeFrameworkVersion>
1011
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1112
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
13+
14+
<!-- Force the CLI to allow us to target higher netcoreapp than it may know about -->
15+
<NETCoreAppMaximumVersion>99.0</NETCoreAppMaximumVersion>
1216
</PropertyGroup>
1317

1418
</Project>

tests/override.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
</ItemGroup>
1919
</Target>
2020

21+
<!-- Remove package references when referencing System.Private.CoreLib from SDK style project -->
22+
<Target Name="CleanResolvedCompileFileDefinitions" AfterTargets="ResolvePackageAssets" Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true' and '$(UsingMicrosoftNETSdk)' == 'true'" >
23+
<ItemGroup>
24+
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)" />
25+
</ItemGroup>
26+
</Target>
27+
2128
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
2229
<!--
2330
Allow this project to setup the default target frameworks. Note this depends on the targeting packs that VS

tests/runtest.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ $(_XunitEpilog)
8080
8181
<PropertyGroup>
8282
<OutputPath>$(XUnitTestBinBase)\$(CategoryWithSlash)</OutputPath>
83-
</PropertyGroup>
83+
<RuntimeFrameworkVersion>$(MicrosoftNETCoreRuntimeCoreCLRPackageVersion)</RuntimeFrameworkVersion>
84+
</PropertyGroup>
8485
8586
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
8687

tests/src/CLRTest.Execute.Batch.targets

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,6 @@ set CLRTestExitCode=!ERRORLEVEL!
299299
<!-- Raise an error if any value in _RequiredProperties is missing -->
300300
<Error Condition=" '%(_RequiredProperties.Value)'=='' "
301301
Text="Missing required test property [%(_RequiredProperties.Identity)]. Something isn't plumbed through correctly. Contact $(_CLRTestBuildSystemOwner)." />
302-
<!-- TODO: this is weird. Consider eliminating it. -->
303-
<GenerateParamList ArgumentItems="@(BatchCLRTestExecutionScriptArgument)">
304-
<Output TaskParameter="ParamList" PropertyName="_CLRTestParamList"/>
305-
</GenerateParamList>
306-
307302
<PropertyGroup>
308303
<!--
309304
This generates the script portion to parse all of the command line arguments.
@@ -339,7 +334,7 @@ goto ArgsDone
339334
340335
:USAGE
341336
ECHO.Usage
342-
ECHO %0 $(_CLRTestParamList)
337+
ECHO %0 @(BatchCLRTestExecutionScriptArgument -> '[-%(Identity) %(ParamName)]', ' ')
343338
ECHO.
344339
ECHO - OPTIONS -
345340
@(BatchCLRTestExecutionScriptArgument -> 'ECHO -%(Identity) %(ParamName)

tests/src/CLRTest.Execute.targets

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,6 @@ This file contains the logic for providing Execution Script generation.
3333
<HasParam>false</HasParam>
3434
</CLRTestExecutionScriptArgument>
3535
</ItemDefinitionGroup>
36-
37-
<!--
38-
TASK: GenerateParamList
39-
This task takes a list of CLRTestExecutionScriptArgument items and
40-
returns a string fit for the usage help message.
41-
example:
42-
[-arg1 param1] [-arg2] [-arg3 param3]
43-
-->
44-
<UsingTask
45-
TaskName="GenerateParamList"
46-
TaskFactory="CodeTaskFactory"
47-
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
48-
<ParameterGroup>
49-
<ArgumentItems ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true"/>
50-
<ParamList ParameterType="System.String" Output="true"/>
51-
</ParameterGroup>
52-
<Task>
53-
<Reference Include="System.Core"/>
54-
<Using Namespace="System"/>
55-
<Using Namespace="System.Linq"/>
56-
<Code Type="Fragment" Language="cs"><![CDATA[
57-
Func<string, bool> parseBool = s =>
58-
{
59-
bool value;
60-
var success = bool.TryParse(s, out value);
61-
if (success)
62-
return value;
63-
return false;
64-
};
65-
var items = ArgumentItems.Select(i => new { Item=i, HasParam=parseBool(i.GetMetadata("HasParam"))});
66-
var noArg = items.Where(i => !i.HasParam).Select(i => new { Identity=i.Item.ItemSpec});
67-
var haveArg = items.Where(i => i.HasParam).Select(i => new { Identity=i.Item.ItemSpec, Name=i.Item.GetMetadata("ParamName")});
68-
ParamList = haveArg.Aggregate("", (s,i) => string.Format("{0} [-{1} {2}]", s, i.Identity, i.Name)) +
69-
noArg.Aggregate("", (s,i) => string.Format("{0} [-{1}]", s, i.Identity));
70-
]]>
71-
</Code>
72-
</Task>
73-
</UsingTask>
7436

7537
<!--
7638
*******************************************************************************************

tests/src/Common/Coreclr.TestWrapper/Coreclr.TestWrapper.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22

3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('dependencies.props', '$(MSBuildThisFileDirectory)../'))" />
34
<Import Project="$([MSBuild]::GetPathOfFileAbove('dir.sdkbuild.props', '$(MSBuildThisFileDirectory)../'))" />
45

56
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<!--
3+
Common files don't take part in the root tests\src\Directory.Build.props
4+
This file prevents them from including it as it gets included in its place
5+
If they ever need to take part, we can conditionally include them as documented
6+
here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
7+
-->
8+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<!--
3+
Common files don't take part in the root tests\src\Directory.Build.targets
4+
This file prevents them from including it as it gets included in its place
5+
If they ever need to take part, we can conditionally include them as documented
6+
here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
7+
-->
8+
</Project>

0 commit comments

Comments
 (0)