Repository navigation
AssetCompiler: the package is build-only, a plain PackageReference or #:package is enough #3570
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| using NuGet.Configuration; | ||
| using NuGet.Frameworks; | ||
| using NuGet.LibraryModel; | ||
| using NuGet.Packaging; | ||
| using NuGet.ProjectModel; | ||
| using NuGet.Protocol; | ||
| using NuGet.Protocol.Core.Types; | ||
|
|
@@ -222,6 +223,7 @@ public static (RestoreRequest, RestoreResult) Restore(ILogger logger, NuGetFrame | |
| var assemblies = new List<string>(); | ||
|
|
||
| var projectPath = Path.Combine("StrideNugetResolver.json"); | ||
| var packagesPath = SettingsUtility.GetGlobalPackagesFolder(settings); | ||
| var spec = new PackageSpec() | ||
| { | ||
| Name = Path.GetFileNameWithoutExtension(projectPath), // make sure this package never collides with a dependency | ||
|
|
@@ -235,7 +237,8 @@ public static (RestoreRequest, RestoreResult) Restore(ILogger logger, NuGetFrame | |
| new LibraryDependency | ||
| { | ||
| LibraryRange = new LibraryRange(packageName, versionRange, LibraryDependencyTarget.Package), | ||
| } | ||
| }, | ||
| .. GetRuntimeExcludedDependencies(packagesPath, packageName, versionRange, nugetFramework), | ||
| ], | ||
| } | ||
| }, | ||
|
|
@@ -249,7 +252,7 @@ public static (RestoreRequest, RestoreResult) Restore(ILogger logger, NuGetFrame | |
| OutputPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "stride", "nugetresolver", $"{packageName}-{versionRange.MinVersion.ToString()}-{nugetFramework.GetShortFolderName()}-{runtimeIdentifier}"), | ||
| OriginalTargetFrameworks = new[] { nugetFramework.GetShortFolderName() }, | ||
| ConfigFilePaths = settings.GetConfigFilePaths(), | ||
| PackagesPath = SettingsUtility.GetGlobalPackagesFolder(settings), | ||
| PackagesPath = packagesPath, | ||
| Sources = SettingsUtility.GetEnabledSources(settings).ToList(), | ||
| FallbackFolders = SettingsUtility.GetFallbackPackageFolders(settings).ToList() | ||
| }, | ||
|
|
@@ -322,5 +325,39 @@ public static (RestoreRequest, RestoreResult) Restore(ILogger logger, NuGetFrame | |
| throw new InvalidOperationException("Unreachable code"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The dependencies a build-only package (no lib/, e.g. Stride.AssetCompiler, a tool that runs from its own | ||
| /// package) keeps out of its consumers' runtime, read from its nuspec in the global packages folder. They are | ||
| /// the package's own runtime dependencies, so they are restored as direct dependencies to get their runtime | ||
| /// assets. None for a package with a lib/ folder, one not in the global packages folder yet, or an inexact version. | ||
| /// </summary> | ||
| private static IEnumerable<LibraryDependency> GetRuntimeExcludedDependencies(string packagesPath, string packageName, VersionRange versionRange, NuGetFramework nugetFramework) | ||
| { | ||
| if (!versionRange.HasLowerAndUpperBounds || versionRange.MinVersion != versionRange.MaxVersion) | ||
| return []; | ||
|
|
||
| var pathResolver = new VersionFolderPathResolver(packagesPath); | ||
| var nuspecPath = pathResolver.GetManifestFilePath(packageName, versionRange.MinVersion); | ||
| if (!File.Exists(nuspecPath) || Directory.Exists(Path.Combine(pathResolver.GetInstallPath(packageName, versionRange.MinVersion), "lib"))) | ||
| return []; | ||
|
Comment on lines
+340
to
+343
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reads the nuspec before the restore, and only from the user-level packages folder. If the game restores somewhere else ( Suggestion: if the nuspec is missing, restore first, read the nuspec from the restored package, then restore again. |
||
|
|
||
| var dependencyGroup = NuGetFrameworkUtility.GetNearest(new NuspecReader(nuspecPath).GetDependencyGroups(), nugetFramework); | ||
| if (dependencyGroup == null) | ||
| return []; | ||
|
|
||
| return dependencyGroup.Packages | ||
| .Where(dependency => | ||
| { | ||
| var includeFlags = dependency.Include.Count > 0 ? LibraryIncludeFlagUtils.GetFlags(dependency.Include) : LibraryIncludeFlags.All; | ||
| includeFlags &= ~LibraryIncludeFlagUtils.GetFlags(dependency.Exclude); | ||
| return (includeFlags & LibraryIncludeFlags.Runtime) == 0; | ||
| }) | ||
| .Select(dependency => new LibraryDependency | ||
| { | ||
| LibraryRange = new LibraryRange(dependency.Id, dependency.VersionRange, LibraryDependencyTarget.Package), | ||
| }) | ||
| .ToList(); | ||
| } | ||
| } | ||
| } | ||
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.
With
ReferenceOutputAssembly="false", NuGet drops this dependency from the nuspec. It was the only path from Stride.GameStudio to Stride.AssetCompiler.The CLI installs only Stride.GameStudio, then looks for the Stride.AssetCompiler package. On a clean cache,
stride upgradefails with "couldn't locate its Asset Compiler", andstride newkeeps the old version.We need to keep the dependency in the nuspec somehow.