Skip to content
Permalink
Browse files

[Assets] Package can now also represent a csproj + package (only new …

…game creation is working)
  • Loading branch information
xen2 committed Aug 29, 2018
1 parent a3bbc24 commit 1fd003ca0b7b5953d4a96ceebc50d6094722593d
Showing with 349 additions and 520 deletions.
  1. +75 −42 sources/assets/Xenko.Core.Assets/Package.cs
  2. +12 −0 sources/assets/Xenko.Core.Assets/PackageCollection.cs
  3. +100 −67 sources/assets/Xenko.Core.Assets/PackageSession.cs
  4. +2 −273 sources/assets/Xenko.Core.Assets/PackageSessionHelper.cs
  5. +1 −1 sources/assets/Xenko.Core.Assets/VSProjectHelper.cs
  6. +22 −22 sources/core/Xenko.Core.Design/VisualStudio/Project.cs
  7. +3 −3 sources/core/Xenko.Core.Design/VisualStudio/Solution.cs
  8. +10 −8 sources/core/Xenko.Core.Design/VisualStudio/SolutionReader.cs
  9. +1 −1 sources/core/Xenko.Core.Design/VisualStudio/SolutionWriter.cs
  10. +1 −1 sources/editor/Xenko.Assets.Presentation/AssetEditors/ProjectWatcher.cs
  11. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/Core/Common.PropertyGroups.targets.t4
  12. +2 −2 ...editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.Android/$ProjectName$.csproj.t4
  13. +1 −1 ...s/editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.Linux/$ProjectName$.csproj.t4
  14. +2 −2 ...Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.UWP/CoreWindow/$ProjectName$.csproj.t4
  15. +2 −2 ...ditor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.UWP/Xaml/$ProjectName$.csproj.t4
  16. +1 −1 ...editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.Windows/$ProjectName$.csproj.t4
  17. +2 −2 ...ces/editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.iOS/$ProjectName$.csproj.t4
  18. +2 −2 ...s/editor/Xenko.Assets.Presentation/Templates/Core/ProjectExecutable.macOS/$ProjectName$.csproj.t4
  19. +2 −0 sources/editor/Xenko.Assets.Presentation/Templates/Core/ProjectLibrary.Game/$ProjectName$.csproj.t4
  20. +62 −65 sources/editor/Xenko.Assets.Presentation/Templates/NewGameTemplateGenerator.cs
  21. +3 −3 sources/editor/Xenko.Assets.Presentation/Templates/ProjectLibraryTemplateGenerator.cs
  22. +1 −1 sources/editor/Xenko.Core.Assets.Editor/Components/TemplateDescriptions/SessionTemplateGenerator.cs
  23. +7 −6 sources/editor/Xenko.Core.Assets.Editor/ViewModel/PackageViewModel.cs
  24. +1 −1 sources/editor/Xenko.Core.Assets.Editor/ViewModel/SessionViewModel.cs
  25. +32 −12 sources/engine/Xenko.Assets/Templates/ProjectTemplateGeneratorHelper.cs
  26. +1 −1 sources/engine/Xenko.Assets/XenkoPackageUpgrader.cs
@@ -21,6 +21,7 @@
using Xenko.Core.Reflection;
using Xenko.Core.Serialization;
using Xenko.Core.Yaml;
using NuGet.ProjectModel;

namespace Xenko.Core.Assets
{
@@ -49,6 +50,17 @@ public enum PackageState
AssetsReady,
}

public enum PackageType
{
/// <summary>
/// Typically from a NuGet folder.
/// </summary>
Standalone,

ProjectOnly,
ProjectAndPackage,
}

/// <summary>
/// A package managing assets.
/// </summary>
@@ -69,6 +81,9 @@ public sealed partial class Package : IIdentifiable, IFileSynchronizable, IAsset
/// </summary>
internal bool IsIdLocked;

[DataMemberIgnore]
public VisualStudio.Project VSProject;

private readonly List<UFile> filesToDelete = new List<UFile>();

private PackageSession session;
@@ -198,6 +213,18 @@ public Guid Id
[DataMember(100)]
public RootAssetCollection RootAssets { get; private set; } = new RootAssetCollection();

/// <summary>
/// Type of package.
/// </summary>
[DataMemberIgnore]
public PackageType Type { get; set; } = PackageType.Standalone;

[DataMemberIgnore]
public List<LockFileLibrary> Dependencies { get; } = new List<LockFileLibrary>();

[DataMemberIgnore]
public List<Package> LoadedDependencies { get; } = new List<Package>();

/// <summary>
/// Gets the loaded templates from the <see cref="TemplateFolders"/>
/// </summary>
@@ -220,6 +247,9 @@ public Guid Id
// TODO: turn that internal!
public List<AssetItem> TemporaryAssets { get; } = new List<AssetItem>();

[DataMemberIgnore]
public List<LockFileLibrary> TopLevelDependencies { get; } = new List<LockFileLibrary>();

/// <summary>
/// Gets the path to the package file. May be null if the package was not loaded or saved.
/// </summary>
@@ -237,6 +267,9 @@ public UFile FullPath
}
}

[DataMemberIgnore]
public UFile ProjectFullPath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this instance has been modified since last saving.
/// </summary>
@@ -489,6 +522,9 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
return;
}

if (Type == PackageType.ProjectOnly)
return;

saveParameters = saveParameters ?? PackageSaveParameters.Default();

// Use relative paths when saving
@@ -1137,56 +1173,55 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters
if (log == null) throw new ArgumentNullException(nameof(log));
if (loadParameters == null) throw new ArgumentNullException(nameof(loadParameters));
var assemblyContainer = loadParameters.AssemblyContainer ?? AssemblyContainer.Default;
foreach (var profile in Profiles)

if (ProjectFullPath != null)
{
foreach (var projectReference in profile.ProjectReferences.Where(projectRef => projectRef.Type == ProjectType.Plugin || projectRef.Type == ProjectType.Library))
{
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
continue;
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, ProjectFullPath, ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;

string assemblyPath = null;
var fullProjectLocation = UPath.Combine(RootDirectory, projectReference.Location).ToWindowsPath();
string assemblyPath = null;
var fullProjectLocation = ProjectFullPath.ToWindowsPath();

try
try
{
var forwardingLogger = new ForwardingLoggerResult(log);
assemblyPath = VSProjectHelper.GetOrCompileProjectAssembly(Session?.SolutionPath, fullProjectLocation, forwardingLogger, "Build", loadParameters.AutoCompileProjects, loadParameters.BuildConfiguration, extraProperties: loadParameters.ExtraCompileProperties, onlyErrors: true);
if (String.IsNullOrWhiteSpace(assemblyPath))
{
var forwardingLogger = new ForwardingLoggerResult(log);
assemblyPath = VSProjectHelper.GetOrCompileProjectAssembly(Session?.SolutionPath, fullProjectLocation, forwardingLogger, "Build", loadParameters.AutoCompileProjects, loadParameters.BuildConfiguration, extraProperties: loadParameters.ExtraCompileProperties, onlyErrors: true);
if (String.IsNullOrWhiteSpace(assemblyPath))
{
log.Error($"Unable to locate assembly reference for project [{fullProjectLocation}]");
continue;
}
log.Error($"Unable to locate assembly reference for project [{fullProjectLocation}]");
return;
}

var loadedAssembly = new PackageLoadedAssembly(projectReference, assemblyPath);
LoadedAssemblies.Add(loadedAssembly);
var loadedAssembly = new PackageLoadedAssembly(projectReference, assemblyPath);
LoadedAssemblies.Add(loadedAssembly);

if (!File.Exists(assemblyPath) || forwardingLogger.HasErrors)
{
log.Error($"Unable to build assembly reference [{assemblyPath}]");
continue;
}
if (!File.Exists(assemblyPath) || forwardingLogger.HasErrors)
{
log.Error($"Unable to build assembly reference [{assemblyPath}]");
return;
}

var assembly = assemblyContainer.LoadAssemblyFromPath(assemblyPath, log);
if (assembly == null)
{
log.Error($"Unable to load assembly reference [{assemblyPath}]");
}
var assembly = assemblyContainer.LoadAssemblyFromPath(assemblyPath, log);
if (assembly == null)
{
log.Error($"Unable to load assembly reference [{assemblyPath}]");
}

loadedAssembly.Assembly = assembly;
loadedAssembly.Assembly = assembly;

if (assembly != null)
{
// Register assembly in the registry
AssemblyRegistry.Register(assembly, AssemblyCommonCategories.Assets);
}
}
catch (Exception ex)
if (assembly != null)
{
log.Error($"Unexpected error while loading project [{fullProjectLocation}] or assembly reference [{assemblyPath}]", ex);
// Register assembly in the registry
AssemblyRegistry.Register(assembly, AssemblyCommonCategories.Assets);
}
}
catch (Exception ex)
{
log.Error($"Unexpected error while loading project [{fullProjectLocation}] or assembly reference [{assemblyPath}]", ex);
}
}
}

@@ -1218,11 +1253,9 @@ internal void UpdateSourceFolders(IReadOnlyCollection<AssetItem> assets)
{
if (asset.SourceFolder == null)
{
//var assetProjectFolder = asset.Location.FullPath;
var lib = sharedProfile.ProjectReferences.FirstOrDefault(x => x.Type == ProjectType.Library && asset.Location.FullPath.StartsWith(x.Location.GetFileNameWithoutExtension()));
if (lib != null)
if (ProjectFullPath != null)
{
asset.SourceProject = UPath.Combine(asset.Package.RootDirectory, lib.Location);
asset.SourceProject = ProjectFullPath;
asset.SourceFolder = asset.SourceProject.GetFullDirectory().GetParent().MakeRelative(RootDirectory);
asset.IsDirty = true;
}
@@ -1,5 +1,6 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using NuGet.ProjectModel;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -60,6 +61,17 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

/// <summary>
/// Finds the a package already in this collection from the specified dependency.
/// </summary>
/// <param name="packageDependency">The package dependency.</param>
/// <returns>Package.</returns>
public Package Find(LockFileLibrary lockFileLibrary)
{
if (lockFileLibrary == null) throw new ArgumentNullException(nameof(lockFileLibrary));
return Find(lockFileLibrary.Name, new PackageVersionRange(new PackageVersion(lockFileLibrary.Version.Version, lockFileLibrary.Version.Release)));
}

/// <summary>
/// Finds the specified package by its unique identifier.
/// </summary>

0 comments on commit 1fd003c

Please sign in to comment.
You can’t perform that action at this time.