Skip to content

Spectre.Console repo fixes #248

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 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<PatchesDir>$(ProjectDir)patches/</PatchesDir>
<!-- if we're not currently building, Visual Studio will still set this -->
<SDK_VERSION Condition="'$(SDK_VERSION)' == ''">$(NETCoreSdkVersion)</SDK_VERSION>
<XPlatTasksDir>$(MSBuildThisFileDirectory)eng/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/</XPlatTasksDir>
<XPlatTasksBinDir>$(XPlatTasksDir)bin/$(Configuration)/</XPlatTasksBinDir>
<XPlatSourceBuildTasksAssembly>$(XPlatTasksBinDir)Microsoft.DotNet.SourceBuild.Tasks.XPlat.dll</XPlatSourceBuildTasksAssembly>
<SdkReferenceDir>$(DotNetCliToolDir)sdk/$(SDK_VERSION)/</SdkReferenceDir>
</PropertyGroup>

<!--
Expand Down
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ while [[ -h $source ]]; do
done

scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"

sdkLine=$(grep -m 1 'dotnet' "$scriptroot/global.json")
sdkPattern="\"dotnet\" *: *\"(.*)\""
if [[ $sdkLine =~ $sdkPattern ]]; then
export SDK_VERSION=${BASH_REMATCH[1]}
fi

"$scriptroot/eng/common/build.sh" --build --restore "$@"
3 changes: 3 additions & 0 deletions eng/Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<Project>

<ItemGroup>
<ProjectToBuild Include="$(RepoRoot)eng\tasks\Microsoft.DotNet.SourceBuild.Tasks.XPlat\*.csproj">
<BuildInParallel>false</BuildInParallel>
</ProjectToBuild>
<ProjectToBuild Include="$(RepoRoot)repo-projects\*.proj" />
</ItemGroup>

Expand Down
26 changes: 26 additions & 0 deletions eng/tasks/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<!-- Build all tasks as AnyCPU to match NuGet DLLs in the SDK: avoid warnings. -->
<Platform>AnyCPU</Platform>
<!--
Do not import the Arcade SDK for the local tooling projects. This lets us
build them with just the .NET SDK, simplifying the build.
-->
<SkipArcadeSdkImport>true</SkipArcadeSdkImport>
</PropertyGroup>

<!--
Use some assemblies from the SDK, instead of package references. This ensures they match what's
found when the task is loaded by the SDK's MSBuild.
-->
<ItemGroup>
<SdkAssembly Include="$(SdkReferenceDir)Newtonsoft.Json.dll" />

<SdkAssemblyReference
Include="@(SdkAssembly -> '%(FileName)')"
HintPath="$(SdkReferenceDir)%(Identity).dll" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<OutputPath>$(XPlatTasksBinDir)</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build">
<Version>15.7.179</Version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to encapsulate this version in versions.props? It would make updating easier and follow the arcade patterns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll log a separate issue for that since it should be done for all the other relevant external repos as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</PackageReference>
<PackageReference Include="Microsoft.Build.Framework">
<Version>15.7.179</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Tasks.Core">
<Version>15.7.179</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Utilities.Core">
<Version>15.7.179</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="@(SdkAssemblyReference)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.DotNet.Build.Tasks
{
// Takes a path to a path to a json file and a
// string that represents a dotted path to an attribute
// and updates that attribute with the new value provided.
public class UpdateJson : Task
{
[Required]
public string JsonFilePath { get; set; }

[Required]
public string PathToAttribute { get; set; }

[Required]
public string NewAttributeValue { get; set; }

public bool SkipUpdateIfMissingKey { get; set; }

public override bool Execute()
{
JObject jsonObj = JObject.Parse(File.ReadAllText(JsonFilePath));

string[] escapedPathToAttributeParts = PathToAttribute.Replace("\\.", "\x1F").Split('.');
for (int i = 0; i < escapedPathToAttributeParts.Length; ++i)
{
escapedPathToAttributeParts[i] = escapedPathToAttributeParts[i].Replace("\x1F", ".");
}
UpdateAttribute(jsonObj, escapedPathToAttributeParts, NewAttributeValue);

File.WriteAllText(JsonFilePath, jsonObj.ToString());
return true;
}

private void UpdateAttribute(JToken jsonObj, string[] path, string newValue)
{
string pathItem = path[0];
if (jsonObj[pathItem] == null)
{
string message = $"Path item [{nameof(PathToAttribute)}] not found in json file.";
if (SkipUpdateIfMissingKey)
{
Log.LogMessage(MessageImportance.Low, $"Skipping update: {message} {pathItem}");
return;
}
throw new ArgumentException(message, pathItem);
}

if (path.Length == 1)
{
jsonObj[pathItem] = newValue;
return;
}

UpdateAttribute(jsonObj[pathItem], path.Skip(1).ToArray(), newValue);
}
}
}
1 change: 1 addition & 0 deletions repo-projects/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SourceBuild.AddSourceToNuGetConfig" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" />
<UsingTask TaskName="UpdateJson" AssemblyFile="$(XPlatSourceBuildTasksAssembly)" />

<Target Name="BuildRepoReferences" Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
<Message Importance="High" Text="Building dependencies [@(RepositoryReference)] needed by '$(RepositoryName)'." />
Expand Down
3 changes: 3 additions & 0 deletions repo-projects/spectre-console.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<PropertyGroup>
<PackagesOutput>$(ProjectDirectory)/src/Spectre.Console/bin/$(Configuration)/</PackagesOutput>
<SpectreConsolePackageVersion>0.48.0</SpectreConsolePackageVersion>

<!-- Defining this ensures global.json gets rewritten to target the current SDK version -->
<GlobalJsonFile>$(ProjectDirectory)/global.json</GlobalJsonFile>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
Expand Down