-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add infrastructure for trimming and NativeAOT test apps. #48024
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
Changes from all commits
8b98edf
bcde710
8a2cf98
e1a82f7
505bfa1
2a133af
ad1a15b
f023c56
393deeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<!-- Workaround while there is no SDK available that understands the TFM; suppress unsupported version errors. --> | ||
<NETCoreAppMaximumVersion>99.9</NETCoreAppMaximumVersion> | ||
|
||
<PublishTrimmed>true</PublishTrimmed> | ||
<TrimMode>full</TrimMode> | ||
<PublishSelfContained>true</PublishSelfContained> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<!-- Enable NuGet static graph evaluation to optimize incremental restore --> | ||
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation> | ||
</PropertyGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<!-- Used to silence the warning caused by the workaround for https://github.com/dotnet/runtime/issues/81382 --> | ||
<SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning> | ||
</PropertyGroup> | ||
|
||
<!-- needed to reference a specific version of NetCoreApp. Workaround https://github.com/dotnet/runtime/issues/81382 --> | ||
<ItemGroup> | ||
<FrameworkReference Update="Microsoft.NETCore.App" | ||
RuntimeFrameworkVersion="$(MicrosoftNETCoreAppRuntimeVersion)" /> | ||
|
||
<PackageReference Include="Microsoft.Dotnet.ILCompiler" | ||
Version="$(MicrosoftNETCoreAppRuntimeVersion)" /> | ||
</ItemGroup> | ||
|
||
<!-- | ||
Reference the Microsoft.AspNetCore.App shared framework assemblies with ProjectReference. | ||
This allows for easy dev workflow. Just need to update the product code, and re-run the tests. | ||
--> | ||
<ItemGroup> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did app.ref not work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works, but it is a bit heavier than this approach. For example, the "incremental" run of We can always switch this as we go forward if we need to. But for now I'd rather do the minimal. |
||
<ProjectReference Include="$(RepoRoot)src\DefaultBuilder\src\Microsoft.AspNetCore.csproj" /> | ||
joperezr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>{TargetFramework}</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<RuntimeIdentifier>{RuntimeIdentifier}</RuntimeIdentifier> | ||
<PublishAot>{PublishAot}</PublishAot> | ||
<MicrosoftNETCoreAppRuntimeVersion>{MicrosoftNETCoreAppRuntimeVersion}</MicrosoftNETCoreAppRuntimeVersion> | ||
<RepoRoot>{RepoRoot}</RepoRoot> | ||
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs> | ||
{AdditionalProperties} | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
{RuntimeHostConfigurationOptions} | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
{AdditionalProjectReferences} | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<TrimmingTestDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'trimmingTests'))</TrimmingTestDir> | ||
<TrimmingTestProjectsDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestDir)', 'projects'))</TrimmingTestProjectsDir> | ||
<ProjectTemplate>$(MSBuildThisFileDirectory)project.csproj.template</ProjectTemplate> | ||
|
||
<!-- These test projects cannot be run in helix, since there is nothing to publish. --> | ||
<BuildHelixPayload>false</BuildHelixPayload> | ||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Microsoft.NET.Sdk needs a TFM set. Set a default one. --> | ||
<TargetFramework Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
|
||
<!-- Enforce build order. Ensure the Shared Fx is built before generating and publishing the test apps. --> | ||
<RequiresDelayedBuild>true</RequiresDelayedBuild> | ||
</PropertyGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<Project> | ||
<Import Project="$(RepoRoot)eng\targets\ResolveReferences.targets" /> | ||
eerhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Condition="'@(TestConsoleAppSourceFiles)' == ''" Include="$(MSBuildProjectDirectory)\*.cs" /> | ||
|
||
<TestSupportFiles Include="$(MSBuildThisFileDirectory)SupportFiles\Directory.Build.*"> | ||
<DestinationFolder>$(TrimmingTestDir)</DestinationFolder> | ||
</TestSupportFiles> | ||
</ItemGroup> | ||
|
||
<Target Name="CreateTestDir" | ||
Inputs="@(TestSupportFiles)" | ||
Outputs="@(TestSupportFiles->'%(DestinationFolder)\%(FileName)%(Extension)')"> | ||
<MakeDir Directories="%(TestSupportFiles.DestinationFolder)" /> | ||
<Copy SourceFiles="@(TestSupportFiles)" DestinationFolder="%(TestSupportFiles.DestinationFolder)" /> | ||
</Target> | ||
|
||
<Target Name="GetTestConsoleApps"> | ||
<ItemGroup> | ||
<TestConsoleAppSourceFiles> | ||
<ProjectDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)', '%(Filename)', '$(PackageRID)'))</ProjectDir> | ||
<TestRuntimeIdentifier>$(TargetRuntimeIdentifier)</TestRuntimeIdentifier> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<TargetFramework Condition="'%(TestConsoleAppSourceFiles.TargetOS)' != ''">$(DefaultNetCoreTargetFramework)-%(TestConsoleAppSourceFiles.TargetOS)</TargetFramework> | ||
</TestConsoleAppSourceFiles> | ||
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier below --> | ||
<TestConsoleAppSourceFiles> | ||
<ProjectFile>%(ProjectDir)project.csproj</ProjectFile> | ||
<TestCommand>$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand> | ||
<TestExecutionDirectory>$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory> | ||
</TestConsoleAppSourceFiles> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<TestConsoleApps Include="@(TestConsoleAppSourceFiles->'%(ProjectFile)')"> | ||
<ProjectCompileItems>%(FullPath)</ProjectCompileItems> | ||
</TestConsoleApps> | ||
<TestConsoleApps AdditionalProperties="MSBuildEnableWorkloadResolver=$(MSBuildEnableWorkloadResolver)" Condition="'$(MSBuildEnableWorkloadResolver)' != ''" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="GenerateProjects" | ||
DependsOnTargets="GetTestConsoleApps;CreateTestDir" | ||
Inputs="@(TestConsoleAppSourceFiles);$(ProjectTemplate);@(TestSupportFiles)" | ||
Outputs="%(TestConsoleApps.Identity)"> | ||
<PropertyGroup> | ||
<_projectDir>%(TestConsoleApps.ProjectDir)\</_projectDir> | ||
<_projectFile>%(TestConsoleApps.ProjectFile)</_projectFile> | ||
<_projectSourceFile>%(TestConsoleApps.ProjectCompileItems)</_projectSourceFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(AdditionalProjectReferences)' != ''"> | ||
<_additionalProjectReferenceTemp Include="$(AdditionalProjectReferences)" /> | ||
<_additionalProjectReference Include="<ProjectReference Include="$(LibrariesProjectRoot)%(_additionalProjectReferenceTemp.Identity)\src\%(_additionalProjectReferenceTemp.Identity).csproj" SkipUseReferenceAssembly="true" />" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<_additionalProjectReferencesString>@(_additionalProjectReference, '%0a')</_additionalProjectReferencesString> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<_switchesAsItems Include="%(TestConsoleApps.DisabledFeatureSwitches)" Value="false" /> | ||
<_switchesAsItems Include="%(TestConsoleApps.EnabledFeatureSwitches)" Value="true" /> | ||
|
||
<_propertiesAsItems Include="%(TestConsoleApps.DisabledProperties)" Value="false" /> | ||
<_propertiesAsItems Include="%(TestConsoleApps.EnabledProperties)" Value="true" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<_runtimeHostConfigurationOptionsString>@(_switchesAsItems->'<RuntimeHostConfigurationOption Include="%(Identity)" Value="%(Value)" Trim="true" />', '%0a ')</_runtimeHostConfigurationOptionsString> | ||
<_additionalPropertiesString>@(_propertiesAsItems->'<%(Identity)>%(Value)</%(Identity)>', '%0a ')</_additionalPropertiesString> | ||
</PropertyGroup> | ||
|
||
<MakeDir Directories="$(_projectDir)" /> | ||
<WriteLinesToFile File="$(_projectFile)" | ||
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)') | ||
.Replace('{TargetFramework}', '%(TestConsoleApps.TargetFramework)') | ||
.Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)') | ||
.Replace('{PublishAot}','$(IsNativeAotTestProject)') | ||
.Replace('{MicrosoftNETCoreAppRuntimeVersion}','$(MicrosoftNETCoreAppRuntimeVersion)') | ||
.Replace('{RepoRoot}', '$(RepoRoot)') | ||
.Replace('{ExtraTrimmerArgs}', '%(TestConsoleApps.ExtraTrimmerArgs)') | ||
.Replace('{AdditionalProperties}', '$(_additionalPropertiesString)') | ||
.Replace('{RuntimeHostConfigurationOptions}', '$(_runtimeHostConfigurationOptionsString)') | ||
.Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)') | ||
)" | ||
Overwrite="true" /> | ||
<Copy SourceFiles="$(_projectSourceFile); | ||
@(_additionalProjectSourceFiles)" | ||
DestinationFolder="$(_projectDir)" /> | ||
<Message Text="Generated $(_projectFile)" /> | ||
</Target> | ||
|
||
<Target Name="PublishTrimmedProjects" | ||
DependsOnTargets="GenerateProjects"> | ||
|
||
<MSBuild Projects="@(TestConsoleApps)" | ||
Targets="Restore" | ||
Condition="'$(SkipTrimmingProjectsRestore)' != 'true'" | ||
Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid());Configuration=$(Configuration)" /> | ||
|
||
<MSBuild Projects="@(TestConsoleApps)" | ||
Targets="Publish" | ||
Properties="Configuration=$(Configuration);BuildProjectReferences=false" /> | ||
</Target> | ||
|
||
<Target Name="ExecuteApplications" | ||
DependsOnTargets="PublishTrimmedProjects" | ||
Inputs="%(TestConsoleApps.Identity)" | ||
Outputs="_unused" | ||
Condition="'$(ArchiveTests)' != 'true'"> | ||
|
||
<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems) ..." /> | ||
<Exec IgnoreExitCode="true" Command="%(TestConsoleApps.TestCommand)" StandardOutputImportance="Low" WorkingDirectory="%(TestConsoleApps.TestExecutionDirectory)"> | ||
<Output TaskParameter="ExitCode" PropertyName="ExecutionExitCode" /> | ||
</Exec> | ||
|
||
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) return a non-success exit code." ContinueOnError="ErrorAndContinue" /> | ||
</Target> | ||
|
||
<Target Name="Test" DependsOnTargets="ExecuteApplications" /> | ||
<Target Name="VSTest" DependsOnTargets="Test" /> | ||
|
||
<!-- define Restore/Build to do nothing, for this project only Test does the testing --> | ||
<Target Name="Restore" /> | ||
<Target Name="Build" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Include="UseStartupThrowsForStructContainersTest.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Uh oh!
There was an error while loading. Please reload this page.