Skip to content

Commit

Permalink
Add new target to generate a Packages.Versions.props with all the rel…
Browse files Browse the repository at this point in the history
…evant properties, and remove old custom tasks
  • Loading branch information
radical committed Jul 16, 2024
1 parent 9e519b3 commit 6e07d55
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 88 deletions.
1 change: 1 addition & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<TestArchiveTestsDirForWorkloadTests Condition="'$(TestArchiveTestsDirForWorkloadTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'workload-tests'))</TestArchiveTestsDirForWorkloadTests>
<TestArchiveTestsDirForEndToEndTests Condition="'$(TestArchiveTestsDirForEndToEndTests)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'helix', 'e2e-tests'))</TestArchiveTestsDirForEndToEndTests>
<PlaywrightDependenciesDirectory>$(ArtifactsBinDir)playwright-deps</PlaywrightDependenciesDirectory>
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>

<!-- This is useful for local runs -->
<VSTestResultsDirectory>$(ArtifactsTestResultsDir)</VSTestResultsDirectory>
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Aspire.Workload.Testing.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<InstallWorkloadUsingArtifactsAfterThisTarget />
<TemplateNuGetConfigPath>$(RepoRoot)NuGet.config</TemplateNuGetConfigPath>
<PatchedNuGetConfigPath>$(ArtifactsObjDir)nuget.workload.config</PatchedNuGetConfigPath>
<GeneratedPackagesVersionsPropsPath>$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>

<_GlobalJsonContent>$([System.IO.File]::ReadAllText('$(RepoRoot)global.json'))</_GlobalJsonContent>
<_DotNetCliVersionFromGlobalJson>$([System.Text.RegularExpressions.Regex]::Match($(_GlobalJsonContent), '(%3F&lt;="dotnet": ").*(%3F=")'))</_DotNetCliVersionFromGlobalJson>
Expand Down
90 changes: 2 additions & 88 deletions tests/Shared/Aspire.Workload.Testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -76,97 +76,11 @@
</ItemGroup>
</Target>

<UsingTask TaskName="PrepareNuGetConfigForWorkloadTesting"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<TemplateNuGetConfigPath ParameterType="System.String" Required="true" />
<OutputFile ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Xml.Linq" />
<Using Namespace="System.Xml.XPath" />
<Code Type="Fragment" Language="cs">
<![CDATA[
if (!File.Exists(TemplateNuGetConfigPath))
{
Log.LogError($"Could not find nuget config template at '{TemplateNuGetConfigPath}' .");
return false;
}
// This task adds a nuget packageSource pointing to the locally built nugets.
// And then adds a packageSourceMapping for that source to `*Aspire*` so the
// locally built nugets can be restored from there
// add packageSource
XDocument doc = XDocument.Load(TemplateNuGetConfigPath);
string xpath = "/configuration/packageSources";
XElement packageSources = doc.XPathSelectElement(xpath);
if (packageSources is null)
{
Log.LogError($"Could not find {xpath} in {TemplateNuGetConfigPath}");
return false;
}
// %BUILT_NUGETS_PATH% is set when building the testproject
packageSources.LastNode.AddAfterSelf(
new XElement("add",
new XAttribute("key", "nuget-local"),
new XAttribute("value", "%BUILT_NUGETS_PATH%")));
// add packageSourceMapping
string mappingXpath = "/configuration/packageSourceMapping";
XElement packageSourceMapping = doc.XPathSelectElement(mappingXpath);
if (packageSourceMapping is null)
{
// if mapping has been removed completely then the task needs an update!
throw new InvalidOperationException($"Expected to find {mappingXpath} in {TemplateNuGetConfigPath}");
}
packageSourceMapping.FirstNode.AddBeforeSelf(
new XElement("packageSource",
new XAttribute("key", "nuget-local"),
new XElement("package", new XAttribute("pattern", "*Aspire*"))));
doc.Save(OutputFile);
Log.LogMessage(MessageImportance.Low, $"Generated patched nuget.config at {OutputFile}");
]]>
</Code>
</Task>
</UsingTask>

<!-- For test projects -->

<Target Name="_PatchNuGetConfig" AfterTargets="GetCopyToOutputDirectoryItems" Inputs="$(TemplateNuGetConfigPath)" Outputs="$(PatchedNuGetConfigPath)">
<PrepareNuGetConfigForWorkloadTesting TemplateNuGetConfigPath="$(RepoRoot)NuGet.config" OutputFile="$(PatchedNuGetConfigPath)" />
</Target>

<Target Name="_AddPackageVersionsForUseWithHelix" BeforeTargets="ZipTestArchive">
<PropertyGroup>
<_TestAssetsOutputDir>$(OutputPath)\testassets\</_TestAssetsOutputDir>

<_PackagePropsContents>
<![CDATA[
<Project>
<PropertyGroup>
<PackageVersion>$(PackageVersion)</PackageVersion>
<MicrosoftExtensionsHostingAbstractionsPackageVersion>$(MicrosoftExtensionsHostingAbstractionsPackageVersion)</MicrosoftExtensionsHostingAbstractionsPackageVersion>
<MicrosoftExtensionsHostingPackageVersion>$(MicrosoftExtensionsHostingPackageVersion)</MicrosoftExtensionsHostingPackageVersion>
</PropertyGroup>
</Project>
]]>
</_PackagePropsContents>
</PropertyGroup>

<WriteLinesToFile Lines="$(_PackagePropsContents)" File="$(_TestAssetsOutputDir)\testproject\Directory.Build.Helix.props" Overwrite="true" />
</Target>

<Target Name="CheckForWorkloadInstalled" BeforeTargets="VSTest" Condition="'$(TestsRunningOutsideOfRepo)' == 'true'">
<Error Condition="'$(SdkWithWorkloadForTestingPath)' == '' or !Exists($(SdkWithWorkloadForTestingPath))"
Text="Could not find %24(SdkWithWorkloadForTestingPath)=$(SdkWithWorkloadForTestingPath) . Prepare it by following:
1. .\build.cmd -pack
2. dotnet build tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.csproj /t:InstallWorkloadUsingArtifacts /p:Configuration=$(Configuration)" />
1. .\build.cmd -pack (or ./build.sh on unix)
2. dotnet build tests/workloads.proj /p:Configuration=$(Configuration)" />
</Target>

<Target Name="_ValidateExpectedSetOfPackagesExist" Condition="'$(SkipPackageCheckForWorkloadTesting)' != 'true'">
Expand Down

0 comments on commit 6e07d55

Please sign in to comment.