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

Update to .NET 9 #433

Merged
merged 1 commit into from
Dec 7, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'

- name: Build & test (Release)
run: dotnet test src -c Release --logger "console;verbosity=normal"
Expand Down
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"editorconfig.editorconfig",
"ms-dotnettools.csharp"
]
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG TARGETARCH
WORKDIR /app

Expand All @@ -16,7 +16,7 @@ COPY . ./
RUN dotnet publish src -a $TARGETARCH -c Release -o /app/src/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app
COPY --from=build /app/src/out .
ENTRYPOINT ["dotnet", "UnityNuGet.Server.dll"]
2 changes: 1 addition & 1 deletion examples/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.9"
---
services:
unitynuget:
build: ../..
Expand Down
43 changes: 23 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# UnityNuGet [![Build Status](https://github.com/xoofx/UnityNuGet/workflows/ci/badge.svg?branch=master)](https://github.com/xoofx/UnityNuGet/actions) [![Static Badge](https://img.shields.io/badge/server-status-blue)](https://unitynuget-registry.azurewebsites.net/status) [![Static Badge](https://img.shields.io/badge/server-feed-blue)](https://unitynuget-registry.azurewebsites.net/-/all)

<img align="right" width="160px" height="160px" src="img/unitynuget.png">
<img align="right" width="160px" height="160px" alt="UnityNuGet logo" src="img/unitynuget.png">

This project provides a seamlessly integration of a [curated list](registry.json) of NuGet packages within the Unity Package Manager.

> DISCLAIMER: This is not an official service provided by Unity Technologies Inc.

## Installation

### Add scope registry (manifest.json):
### Add scope registry (manifest.json)

In order to use this service you simply need to edit the `Packages/manifest.json` in your project and add the following scoped registry:

Expand All @@ -24,16 +24,16 @@ In order to use this service you simply need to edit the `Packages/manifest.json
}
],
"dependencies": {
"org.nuget.scriban": "2.1.0"
"org.nuget.scriban": "2.1.0"
}
}
```

### Add scope registry (Package Manager UI):
### Add scope registry (Package Manager UI)

Instructions: https://docs.unity3d.com/Manual/class-PackageManager.html
Instructions: <https://docs.unity3d.com/Manual/class-PackageManager.html>

```
```yaml
Name: Unity NuGet

Url: https://unitynuget-registry.azurewebsites.net
Expand All @@ -43,21 +43,21 @@ Scope(s): org.nuget

### Disable Assembly Version Validation

This step is necessary to ensure that binding redirects for [strongly named assemblies](https://learn.microsoft.com/en-us/dotnet/standard/assembly/strong-named) in NuGet packages resolve correctly to paths _within the Unity project_.
This step is necessary to ensure that binding redirects for [strongly named assemblies](https://learn.microsoft.com/en-us/dotnet/standard/assembly/strong-named) in NuGet packages resolve correctly to paths _within the Unity project_.

- In Unity 2022.2+, this is the [default behavior](https://forum.unity.com/threads/editor-assembly-loading-issues-unloading-broken-assembly-could-not-load-signature.754508/#post-8647791), so no action is required.
- For earlier Unity versions, uncheck "Project Settings > Player > Other Settings > Configuration > Assembly Version Validation"

### Verify installation

> WARNING: If you are encountering weird compilation errors with UnityNuGet and you have been using UnityNuGet already,
> WARNING: If you are encountering weird compilation errors with UnityNuGet and you have been using UnityNuGet already,
> it could be that we have updated packages on the server, and in that case, you need to clear the cache containing
> all Unity NPM packages downdloaded from the `unitynuget-registry.azurewebsites.net` registry.
> all Unity NPM packages downloaded from the `unitynuget-registry.azurewebsites.net` registry.
> On Windows, this cache is located at: `%localappdata%\Unity\cache\npm\unitynuget-registry.azurewebsites.net`
>
> Cache locations by OS: https://docs.unity3d.com/Manual/upm-cache.html
> Cache locations by OS: <https://docs.unity3d.com/Manual/upm-cache.html>

When opening the Package Manager Window, you should see a few packages coming from NuGet (with the postfix text ` (NuGet)`)
When opening the Package Manager Window, you should see a few packages coming from NuGet (with the postfix text ` (NuGet)`)

![UnityEditorWithNuGet](img/unity_editor_with_nuget.jpg)

Expand All @@ -68,31 +68,32 @@ This service provides only a [curated list](registry.json) of NuGet packages
Your NuGet package needs to respect a few constraints in order to be listed in the curated list:

- It must have non-preview versions (e.g `1.0.0` but not `1.0.0-preview.1`)
- It must provide `.NETStandard2.0` assemblies as part of its package
- It must provide at least `.NETStandard2.0` (and optionally `.NETStandard2.1`) assemblies as part of its package

You can send a PR to this repository to modify the [registry.json](registry.json) file (don't forget to maintain the alphabetical order)

You also need to **specify the lowest version of your package that has support for `.NETStandard2.0`** upward so that other packages depending on your package have a chance to work with.

Beware that **all transitive dependencies of the package** must be **explicitly listed** in the registry as well.

> NOTE:
> NOTE:
> * We reserve the right to decline a package to be available through this service
> * The server will be updated only when a new version tag is pushed on the main branch.

## Compatibility

Only compatible with **`Unity 2019.1`** and potentially with newer version.

> NOTE: This service is currently only tested with **`Unity 2019.x, 2020.x and 2021.x`**
> NOTE: This service is currently only tested with **`Unity 2019.x, 2020.x, 2021.x, 2022.x, 2023.x and 6`**
>
> It may not work with a more recent version of Unity

## Docker

> Available in [ghcr (GitHub Container Registry)](https://github.com/xoofx/UnityNuGet/pkgs/container/unitynuget).
>
>
> Supported platforms:
>
> - linux/amd64
> - linux/arm64

Expand Down Expand Up @@ -144,7 +145,7 @@ On Azure through my own Azure credits coming from my MVP subscription, enjoy!

### **Why can't you add all NuGet packages?**

The reason is that many NuGet packages are not compatible with Unity, or do not provide `.NETStandard2.0` assemblies or are not relevant for being used within Unity.
The reason is that many NuGet packages are not compatible with Unity, or do not provide `.NETStandard2.0` or `.NETStandard2.1` assemblies or are not relevant for being used within Unity.

Also currently the Package Manager doesn't provide a way to filter easily packages, so the UI is currently not adequate to list lots of packages.

Expand All @@ -154,19 +155,21 @@ Since 2019.1.x, Unity is compatible with `.NETStandard2.0` and it is the .NET pr

Having a `.NETStandard2.0` for NuGet packages for Unity can ensure that the experience to add a package to your project is consistent and well supported.

> More information: https://docs.unity3d.com/Manual/dotnetProfileSupport.html
As of Unity 2021.x it also supports `.NETStandard2.1` so packages providing this target will be compatible with this version of Unity or newer.

> More information: <https://docs.unity3d.com/Manual/dotnet-profile-support.html>

### **How this service is working?**

This project implements a simplified compatible NPM server in C# using ASP.NET Core and converts NuGet packages to Unity packages before serving them.
This project implements a simplified compatible NPM server in C# using ASP.NET Core and converts NuGet packages to Unity packages before serving them.

Every 10min, packages are updated from NuGet so that if a new version is published, from the curated list of NuGet packages, it will be available through this service.
Every 10 minutes, packages are updated from NuGet so that if a new version is published, from the curated list of NuGet packages, it will be available through this service.

Once converted, these packages are cached on the disk on the server.

## License

This software is released under the [BSD-Clause 2 license](https://opensource.org/licenses/BSD-2-Clause).
This software is released under the [BSD-Clause 2 license](https://opensource.org/licenses/BSD-2-Clause).

## Author

Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<Nullable>enable</Nullable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
46 changes: 23 additions & 23 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.11" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="NuGet.PackageManagement" Version="6.12.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
<PackageVersion Include="NUglify" Version="1.21.10" />
<PackageVersion Include="nunit" Version="4.2.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="Scriban" Version="5.12.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="NuGet.PackageManagement" Version="6.12.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
<PackageVersion Include="NUglify" Version="1.21.10" />
<PackageVersion Include="nunit" Version="4.2.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="Scriban" Version="5.12.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
</Project>
72 changes: 40 additions & 32 deletions src/UnityNuGet.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using UnityNuGet;
using UnityNuGet.Server;

var builder = WebApplication.CreateBuilder(args);

namespace UnityNuGet.Server
{
public static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
// Add the registry cache initializer
builder.Services.AddHostedService<RegistryCacheInitializer>();
// Add the registry cache updater
builder.Services.AddHostedService<RegistryCacheUpdater>();
// Add the registry cache report
builder.Services.AddSingleton<RegistryCacheReport>();
builder.Services.AddSingleton<RegistryCacheSingleton>();

builder.Services.Configure<RegistryOptions>(builder.Configuration.GetSection("Registry"));
builder.Services.AddSingleton<IValidateOptions<RegistryOptions>, ValidateRegistryOptions>();
builder.Services.AddOptionsWithValidateOnStart<RegistryOptions, ValidateRegistryOptions>();

builder.Services.AddApplicationInsightsTelemetry();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
//webBuilder.UseSetting("detailedErrors", "true");
webBuilder.ConfigureServices((context, services) =>
{
// Add the registry cache initializer
services.AddHostedService<RegistryCacheInitializer>();
// Add the registry cache updater
services.AddHostedService<RegistryCacheUpdater>();
// Add the registry cache report
services.AddSingleton<RegistryCacheReport>();
services.AddSingleton<RegistryCacheSingleton>();
// Also enable NewtonsoftJson serialization
builder.Services.AddControllers().AddNewtonsoftJson();

var app = builder.Build();

services.AddOptions<RegistryOptions>()
.Bind(context.Configuration.GetSection("Registry"))
.ValidateDataAnnotations();
});
webBuilder.UseStartup<Startup>();
});
}
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.LogRequestHeaders(app.Services.GetRequiredService<ILoggerFactory>());
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseRouting();
app.MapControllers();
app.MapStatus();

app.Run();
2 changes: 1 addition & 1 deletion src/UnityNuGet.Server/RegistryCacheInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Task StartAsync(CancellationToken cancellationToken)

if (isDevelopment)
{
var currentDirectory = Path.GetDirectoryName(typeof(Startup).Assembly.Location)!;
var currentDirectory = Path.GetDirectoryName(AppContext.BaseDirectory)!;
unityPackageFolder = Path.Combine(currentDirectory, new DirectoryInfo(registryOptions.RootPersistentFolder!).Name);
}
else
Expand Down
11 changes: 10 additions & 1 deletion src/UnityNuGet.Server/RegistryCacheUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,19 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

await Task.Delay((int)_registryOptions.UpdateInterval.TotalMilliseconds, stoppingToken);
}
}
catch (TaskCanceledException)
{
string message = "RegistryCache update canceled";

_logger.LogInformation("{Message}", message);

_registryCacheReport.AddInformation($"{message}.");
_registryCacheReport.Complete();
}
catch (Exception ex)
{
string message = "Error while building a new registry cache.";
string message = "Error while building a new registry cache";

_logger.LogError(ex, "{Message}", message);

Expand Down
42 changes: 0 additions & 42 deletions src/UnityNuGet.Server/Startup.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/UnityNuGet.Server/UnityNuGet.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ApplicationInsightsResourceId>/subscriptions/b6745039-70e7-4641-994b-5457cb220e2a/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/unitynuget-registry</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/b6745039-70e7-4641-994b-5457cb220e2a/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/unitynuget-registry</ApplicationInsightsAnnotationResourceId>
<UserSecretsId>1be0a769-8d75-4a27-99e0-128afcc0ffee</UserSecretsId>
<PublishAot>false</PublishAot>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading
Loading