-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rob Anderson <jamsidedown@users.noreply.github.com> Co-authored-by: Daniel P. Doyle <3020488+TheDanielDoyle@users.noreply.github.com>
- Loading branch information
1 parent
9e8d535
commit 4467adb
Showing
11 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -360,3 +360,5 @@ MigrationBackup/ | |
|
||
**/coveragereport/**/** | ||
src/**/coverage.json | ||
|
||
src/scripts/nuget/** |
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
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,23 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="BlazorInteractive.ConsoleApp" type="DotNetProject" factoryName=".NET Project"> | ||
<option name="EXE_PATH" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/bin/Debug/net7.0/BlazorInteractive.ConsoleApp" /> | ||
<option name="PROGRAM_PARAMETERS" value="" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/bin/Debug/net7.0" /> | ||
<option name="PASS_PARENT_ENVS" value="1" /> | ||
<envs> | ||
<env name="DOTNET_EnableAVX" value="0" /> | ||
</envs> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/BlazorInteractive.ConsoleApp.csproj" /> | ||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> | ||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> | ||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" /> | ||
<option name="PROJECT_KIND" value="DotNetCore" /> | ||
<option name="PROJECT_TFM" value="net7.0" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
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,17 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="BlazorInteractive: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile"> | ||
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BlazorInteractive/BlazorInteractive.csproj" /> | ||
<option name="LAUNCH_PROFILE_TFM" value="net7.0" /> | ||
<option name="LAUNCH_PROFILE_NAME" value="http" /> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" /> | ||
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" /> | ||
<option name="SEND_DEBUG_REQUEST" value="1" /> | ||
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
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,17 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="BlazorInteractive: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile"> | ||
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BlazorInteractive/BlazorInteractive.csproj" /> | ||
<option name="LAUNCH_PROFILE_TFM" value="net7.0" /> | ||
<option name="LAUNCH_PROFILE_NAME" value="https" /> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" /> | ||
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" /> | ||
<option name="SEND_DEBUG_REQUEST" value="1" /> | ||
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
14 changes: 14 additions & 0 deletions
14
src/BlazorInteractive.ConsoleApp/BlazorInteractive.ConsoleApp.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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BlazorInteractive.DependencyManagement\BlazorInteractive.DependencyManagement.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,26 @@ | ||
using BlazorInteractive.DependencyManagement; | ||
using Microsoft.Extensions.Logging; | ||
using OneOf.Types; | ||
|
||
namespace BlazorInteractive.ConsoleApp; | ||
|
||
class Program | ||
{ | ||
private static readonly ILogger _logger; | ||
|
||
async static Task Main(string[] args) | ||
{ | ||
var nugetPackageGetter = new NuGetPackageGetter(_logger); | ||
var package = await nugetPackageGetter.GetPackage("ironpython"); | ||
package.Switch( | ||
success => | ||
{ | ||
Console.WriteLine("Success"); | ||
}, | ||
failure => | ||
{ | ||
Console.WriteLine("Failure"); | ||
} | ||
); | ||
} | ||
} |
87 changes: 84 additions & 3 deletions
87
src/BlazorInteractive.DependencyManagement/NuGetPackageGetter.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 |
---|---|---|
@@ -1,18 +1,99 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System.IO.Compression; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using OneOf.Types; | ||
|
||
namespace BlazorInteractive.DependencyManagement; | ||
|
||
public class NuGetPackageGetter : IPackageGetter | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public NuGetPackageGetter(ILogger<NuGetPackageGetter> logger) | ||
record IndexResource([property:JsonPropertyName("@Id")] string Id, [property:JsonPropertyName("@Type")] string Type, string Comment); | ||
record IndexResponse(string Version, List<IndexResource> Resources); | ||
record PackageVersions(List<string> Versions); | ||
|
||
public NuGetPackageGetter(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public Task<PackageResult> GetPackage(string name) | ||
public async Task<PackageResult> GetPackage(string name) | ||
{ | ||
throw new NotImplementedException(); | ||
Directory.CreateDirectory("nuget"); | ||
|
||
var nugetIndexResponse = await GetAndCache<IndexResponse>("https://api.nuget.org/v3/index.json", "nuget/index.json"); | ||
var packageVersionsBaseUrl = nugetIndexResponse.Resources.First(resource => resource.Type == "PackageBaseAddress/3.0.0").Id; | ||
|
||
var testUrl = $"{packageVersionsBaseUrl}{name}/index.json"; | ||
Console.WriteLine(testUrl); | ||
var versionsResponse = await GetAndCache<PackageVersions>($"{packageVersionsBaseUrl}{name}/index.json", $"nuget/{name}versions.json"); | ||
var latestVersion = versionsResponse.Versions.Last(); | ||
|
||
// https://github.com/dotnet/runtime/issues/78991 | ||
// DOTNET_EnableAVX=0 | ||
var packageUrl = $"{packageVersionsBaseUrl}{name}/{latestVersion}/{name}.{latestVersion}.nupkg"; | ||
// var packageUrl = $"{packageVersionsBaseUrl.ToString()}{name.ToString()}/{latestVersion.ToString()}/{name.ToString()}.{latestVersion.ToString()}.nupkg"; | ||
|
||
if (!File.Exists($"nuget/{name}.{latestVersion}.nupkg")) | ||
{ | ||
using (var localFile = File.OpenWrite($"nuget/{name}.{latestVersion}.nupkg")) | ||
{ | ||
var packageZip = await client.GetStreamAsync(packageUrl); | ||
await packageZip.CopyToAsync(localFile); | ||
} | ||
} | ||
|
||
var extractDir = $"nuget/{name}.{latestVersion}"; | ||
if (!Directory.Exists(extractDir)) | ||
{ | ||
Directory.CreateDirectory(extractDir); | ||
} | ||
|
||
using (var zip = ZipFile.OpenRead($"nuget/{name}.{latestVersion}.nupkg")) | ||
{ | ||
foreach (var file in zip.Entries) | ||
{ | ||
var target = $"{extractDir}/{file.Name}"; | ||
if (File.Exists(target)) | ||
{ | ||
continue; | ||
} | ||
|
||
// Check folders | ||
|
||
if (file.Name.EndsWith(".dll") && file.FullName.Contains("net6")) | ||
{ | ||
file.ExtractToFile(target); | ||
Console.WriteLine($"Extracted {file.FullName}"); | ||
} | ||
else if (file.Name.EndsWith("nuspec")) | ||
{ | ||
file.ExtractToFile(target); | ||
Console.WriteLine($"Extracted {file.FullName}"); | ||
} | ||
} | ||
} | ||
|
||
return new PackageResult(new Success()); | ||
} | ||
|
||
HttpClient client = new(); | ||
|
||
async Task<T> GetAndCache<T>(string url, string file) | ||
{ | ||
string json; | ||
if (!File.Exists(file)) | ||
{ | ||
json = await client.GetStringAsync(url); | ||
await File.WriteAllTextAsync(file, json); | ||
} | ||
else | ||
{ | ||
json = await File.ReadAllTextAsync(file); | ||
} | ||
|
||
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions {PropertyNameCaseInsensitive = true}); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# Scripts | ||
|
||
- [NuGetThosePackages.csx](NuGetThosePackages.csx) | ||
|
||
`dotnet script NuGetThosePackages.csx` | ||
|
||
> System.IO.DirectoryNotFoundException: Could not find a part of the path '../BlazorInteractive/src/scripts/nuget/index.json'. | ||
`mkdir nuget` |
Empty file.