Skip to content

Instantly share code, notes, and snippets.

@manio143
Created October 1, 2023 22:07
Show Gist options
  • Save manio143/4bbfb83ebeb42e54a61444004996f9fd to your computer and use it in GitHub Desktop.
Save manio143/4bbfb83ebeb42e54a61444004996f9fd to your computer and use it in GitHub Desktop.

Project loading

Given path to sln file or project file.

It starts in SessionViewModel.OpenSession with a call to PackageSession.Load. -> writes into sessionResult then it calls PackageSession.LoadMissingReferences finally we create a new SessionViewModel on the UI thread and call LoadAssetsFromPackages on it.

PackageSession.Load

  1. Creates a new PackageSession
    • this holds information about project solution (Stride.Core.VisualStudio abstraction) and collection of projects and packages referenced
  2. If file is a project calls .LoadProject and then .Projects.Add If file is solution, it parses the solution and for C# projects invokes .LoadProject, assigns the solution reference to project and calls .Projects.Add Then calls .LoadMissingDependencies which loads referenced dependencies
  3. Calls .LoadMissingReferences
  4. Runs PackageSessionAnalysis over the session
  5. Runs custom analysis implementations from packages (currently none) plugin point

PackageAnalysis

  1. Converts absolute paths to relative in assets
  2. Tries to update Root assets collection in case there's mismatches Guid/Url
  3. Runs AssetAnalysis over assets, which updates references between assets

PackageSession.LoadProject

  1. Calls Package.LoadProject
  2. Checks if project is legacy Xenko and can be upgraded
  3. Assigns Meta .Name if missing
  4. Adds version constraint if present

Package.LoadProject - supports both projects and packages

  1. If file is a project (.*proj)
    1. Checks if .sdpkg file exists and if the xenko version needs to be renamed
    2. If .sdkpg exists calls LoadRaw else creates a new dirty package with default parameters
  2. If file is .sdpkg calls LoadRaw
    1. If there's a .csproj next to it, treats it like above
    2. otherwise looks for a .nuspec file with same name as package in .. directory, ensures package directory is called stride and parses name of nuspec directory to get package version (assumes being served from NuGet cache)

PackageContainer -> SolutionProject -> StandalonePackage

Package.LoadRaw calls AssetMigration.MigrateAssetIfNeeded and AssetFileSerializer.Load<Package> to deserialize the package.

PackageSession.PreLoadPackageDependencies

  1. uses Microsoft.Build.Evaluation.ProjectCollection to parse *proj file
  2. reads properties (version, name), references
  3. something about package version upgrades
  4. Then for each package reference, try upgrade
  5. NuGet Restore using VSProjectHelper.RestoreNugetPackages
  6. Calls PackageSession.UpdateDependencies
  7. Registers dependencies in AssemblyContainer (core.reflection)
  8. Loads dependencies via PackageSession.LoadProject

PackageSession.UpdateDependencies

  1. Assumes obj folder location and tries to read the project.assets.json
  2. Resolves assembly paths from referenced dependencies (and some metadata). NOTE: when package is a dependency but with PrivateAssets=all and no assembly reference, it effectively doesn't have any metadata in project.assets.json so we won't correctly read it out. We need to somehow populate the CompileTimeAssemblies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment