Skip to content
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

Msbuild tasks. #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference
Include="..\Kuinox.NupkgDeterministicator\Kuinox.NupkgDeterministicator.csproj"
SkipGetTargetFrameworkProperties="true"
ReferenceOutputAssembly="false"
ExcludeAssets="all"
/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.10.4" />
</ItemGroup>


<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\Kuinox.NupkgDeterministicator\bin\$(Configuration)\net6.0\Kuinox.NupkgDeterministicator.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>tools</PackagePath>
<Visible>false</Visible>
</None>
<None Include="$(MSBuildThisFileDirectory)..\Kuinox.NupkgDeterministicator\bin\$(Configuration)\net6.0\Kuinox.NupkgDeterministicator.runtimeconfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>tools</PackagePath>
<Visible>false</Visible>
</None>
</ItemGroup>

</Project>
72 changes: 72 additions & 0 deletions Kuinox.NupkgDeterministicator.Task/MakeNukpkgDeterministic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;

namespace Kuinox.NupkgDeterministicator.Task
{
public sealed class MakeNukpkgDeterministic : ToolTask
{
/// <summary>
/// The zip to make deterministic.
/// </summary>
public string ZipPath { get; set; }

/// <summary>
/// The last write time to sets. Default to 2000-01-01.
/// </summary>
public DateTime LastWriteTime { get; set; } = new DateTime(2000, 1, 1);

Choose a reason for hiding this comment

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

I don't know which PR gets in first, but this creates a semantic merge conflict between them. SOURCE_DATE_EPOCH should clearly be used in the initializer here too.

Copy link
Contributor

@BinToss BinToss Oct 20, 2024

Choose a reason for hiding this comment

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

https://learn.microsoft.com/en-us/dotnet/api/system.datetime.unixepoch?view=net6.0
For later reference, UnixEpoch is pre-defined at this location in the .NET 6 API.


/// <summary>
/// Used to identify the nupkg and symbols package
/// </summary>
public string PackageVersion { get; set; }

protected override string ToolName => Path.GetFileName(GetDotNetPath());

protected override string GenerateCommandLineCommands() => $"exec \"{ToolPath}\"";

protected override string GenerateResponseFileCommands() =>
ZipPath + " " + LastWriteTime.ToString(CultureInfo.InvariantCulture);


private const string DotNetHostPathEnvironmentName = "DOTNET_HOST_PATH";

// https://github.com/dotnet/roslyn/blob/020db28fa9b744146e6f072dbdc6bf3e62c901c1/src/Compilers/Shared/RuntimeHostInfo.cs#L59
private static string GetDotNetPath()
{
if (Environment.GetEnvironmentVariable(DotNetHostPathEnvironmentName) is string pathToDotNet)
{
return pathToDotNet;
}

var (fileName, sep) = Environment.OSVersion.Platform == PlatformID.Win32NT
? ("dotnet.exe", ';')
: ("dotnet", ':');

var path = Environment.GetEnvironmentVariable("PATH") ?? "";
foreach (var item in path.Split(new[] { sep }, StringSplitOptions.RemoveEmptyEntries))
{
try
{
var filePath = Path.Combine(item, fileName);
if (File.Exists(filePath))
{
return filePath;
}
}
catch
{
// If we can't read a directory for any reason just skip it
}
}

return fileName;
}

protected override string GenerateFullPathToTool() => Path.GetFullPath(GetDotNetPath());
}
}
8 changes: 7 additions & 1 deletion Kuinox.NupkgDeterministicator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32408.312
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kuinox.NupkgDeterministicator", "Kuinox.NupkgDeterministicator\Kuinox.NupkgDeterministicator.csproj", "{BA1667CF-66CA-4C07-902A-6C577B1F7ED0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kuinox.NupkgDeterministicator", "Kuinox.NupkgDeterministicator\Kuinox.NupkgDeterministicator.csproj", "{BA1667CF-66CA-4C07-902A-6C577B1F7ED0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kuinox.NupkgDeterministicator.Task", "Kuinox.NupkgDeterministicator.Task\Kuinox.NupkgDeterministicator.Task.csproj", "{CC8B4D54-BCF7-4FB8-B2E0-845380DBAD99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{BA1667CF-66CA-4C07-902A-6C577B1F7ED0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA1667CF-66CA-4C07-902A-6C577B1F7ED0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA1667CF-66CA-4C07-902A-6C577B1F7ED0}.Release|Any CPU.Build.0 = Release|Any CPU
{CC8B4D54-BCF7-4FB8-B2E0-845380DBAD99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC8B4D54-BCF7-4FB8-B2E0-845380DBAD99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC8B4D54-BCF7-4FB8-B2E0-845380DBAD99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC8B4D54-BCF7-4FB8-B2E0-845380DBAD99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down