-
Notifications
You must be signed in to change notification settings - Fork 2
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
Kuinox
wants to merge
1
commit into
master
Choose a base branch
from
feature/msbuildtask
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Kuinox.NupkgDeterministicator.Task/Kuinox.NupkgDeterministicator.Task.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
Kuinox.NupkgDeterministicator.Task/MakeNukpkgDeterministic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
/// <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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.