sdk/test/Directory.Build.targets

84 строки
4.1 KiB
XML

<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(CanRunTestAsTool)' != 'false' AND '$(OutputType)' == 'Exe' AND '$(DotNetBuildSourceOnly)' != 'true'">
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>$(PackageId)</ToolCommandName>
<CanRunTestAsTool Condition="'$(CanRunTestAsTool)' == ''">true</CanRunTestAsTool>
<!-- Put packages for tests in subfolder so we don't try to sign them -->
<PackageOutputPath>$(PackageOutputPath)tests\</PackageOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<!-- Set this to true for test project only because test assets contains .editorconfig file -->
<NoDefaultExcludes>true</NoDefaultExcludes>
</PropertyGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true' AND '$(OutputType)' == 'Exe' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="$(MSBuildThisFileDirectory)Common\Program.cs" />
</ItemGroup>
<Target Name="TestAsTool" DependsOnTargets="Pack;_InnerGetTestsToRun">
<PropertyGroup>
<TestLocalToolFolder>$(ArtifactsTmpDir)$(ToolCommandName)\</TestLocalToolFolder>
<TestLocalToolExecutionFolder>$(ArtifactsTmpDir)$(ToolCommandName)\w</TestLocalToolExecutionFolder>
<DOTNET_CLI_HOME>$(ArtifactsTmpDir)DOTNET_CLI_HOME\</DOTNET_CLI_HOME>
</PropertyGroup>
<RemoveDir Directories="$(TestLocalToolExecutionFolder)" />
<RemoveDir Directories="$(TestLocalToolFolder)" />
<MakeDir Directories="$(TestLocalToolFolder)" />
<MakeDir Directories="$(TestLocalToolExecutionFolder)" />
<MakeDir Directories="$(ArtifactsTestResultsDir)" />
<!-- Remove tool package from NuGet cache, so that local changes will be reflected if the package version
hasn't changed. -->
<RemoveDir Directories="$(NuGetPackageRoot)$(ToolCommandName)\$(PackageVersion)" />
<Exec Command="dotnet new tool-manifest"
IgnoreStandardErrorWarningFormat="true"
WorkingDirectory="$(TestLocalToolFolder)"
EnvironmentVariables="DOTNET_CLI_HOME=$(DOTNET_CLI_HOME)"/>
<Exec Command="dotnet tool install --local $(ToolCommandName) --version $(PackageVersion) --add-source $(ArtifactsNonShippingPackagesDir)"
WorkingDirectory="$(TestLocalToolFolder)"
EnvironmentVariables="DOTNET_CLI_HOME=$(DOTNET_CLI_HOME)"/>
<Exec Command="dotnet tool restore"
WorkingDirectory="$(TestLocalToolFolder)"
EnvironmentVariables="DOTNET_CLI_HOME=$(DOTNET_CLI_HOME)"/>
<PropertyGroup>
<ResultsXmlPath>@(TestToRun->'%(ResultsXmlPath)')</ResultsXmlPath>
<ResultsHtmlPath>@(TestToRun->'%(ResultsHtmlPath)')</ResultsHtmlPath>
<ResultsStdOutPath>@(TestToRun->'%(ResultsStdOutPath)')</ResultsStdOutPath>
<TestArgs>-noautoreporters -noRepoInference</TestArgs>
<TestArgs>$(TestArgs) -dotnetPath $(ArtifactsBinDir)redist\$(Configuration)\dotnet\dotnet</TestArgs>
<TestArgs>$(TestArgs) -xml "$(ResultsXmlPath)"</TestArgs>
<TestArgs>$(TestArgs) -html "$(ResultsHtmlPath)" $(TestRunnerAdditionalArguments)</TestArgs>
<TestArgs>$(TestArgs) &gt; $(ResultsStdOutPath)</TestArgs>
<TestArgs>$(TestArgs) -testExecutionDirectory $(TestLocalToolExecutionFolder)</TestArgs>
</PropertyGroup>
<!-- Run "dotnet new" (which will just display usage and available templates) in order to print first time
use message so that it doesn't interfere with tests which check the output of commands. -->
<Exec Command="$(ArtifactsBinDir)redist\$(Configuration)\dotnet\dotnet new" />
<Exec Command="dotnet tool run $(ToolCommandName) -- $(TestArgs)"
WorkingDirectory="$(TestLocalToolFolder)"
EnvironmentVariables="DOTNET_CLI_HOME=$(DOTNET_CLI_HOME)"
IgnoreStandardErrorWarningFormat="true" />
</Target>
<Import Project="..\Directory.Build.targets" />
</Project>