Skip to content
Permalink
Browse files

[Assets] Package upgrade is now working for 3.0 projects

  • Loading branch information
xen2 committed Dec 5, 2018
1 parent aa227b3 commit c1904fc846dd801426dc9b07eeada6df3db8ab38
@@ -1278,9 +1278,9 @@ protected override void UpgradeAsset(AssetMigrationContext context, PackageVersi

for (int i = 0; i < profile.ResourceFolders.Count; ++i)
{
var resourcePath = UPath.Combine(assetFile.OriginalFilePath.GetFullDirectory(), (UDirectory)(string)profile.ResourceFolders[i].Path);
var resourcePath = UPath.Combine(assetFile.OriginalFilePath.GetFullDirectory(), (UDirectory)(string)profile.ResourceFolders[i]);
resourcePath = resourcePath.MakeRelative(assetFile.FilePath.GetFullDirectory());
profile.ResourceFolders[i].Path = (string)resourcePath;
profile.ResourceFolders[i] = (string)resourcePath;
}

asset.AssetFolders = profile.AssetFolders;
@@ -121,6 +121,20 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
if (packageReference.HasMetadata("Version") && PackageVersionRange.TryParse(packageReference.GetMetadataValue("Version"), out var packageRange))
packageReferences[packageReference.EvaluatedInclude] = packageRange;
}

// Need to go recursively
foreach (var projectReference in msProject.GetItems("ProjectReference").ToList())
{
var projectFile = new UFile(Path.Combine(Path.GetDirectoryName(project.FullPath), projectReference.EvaluatedInclude));
if (File.Exists(projectFile))
{
var referencedProject = Projects.OfType<SolutionProject>().FirstOrDefault(x => x.FullPath == new UFile(projectFile));
if (referencedProject != null)
{
await PreLoadPackageDependencies(log, referencedProject, loadParameters);
}
}
}
}
finally
{
@@ -401,6 +401,11 @@ public sealed class ProjectCollection : ObservableCollection<PackageContainer>
/// </summary>
public sealed partial class PackageSession : IDisposable, IAssetFinder
{
internal static readonly string SolutionHeader = @"Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = {0}
MinimumVisualStudioVersion = {0}".ToFormat(DefaultVisualStudioVersion);

/// <summary>
/// The visual studio version property used for newly created project solution files
/// </summary>
@@ -426,7 +431,7 @@ public sealed partial class PackageSession : IDisposable, IAssetFinder
public PackageSession()
{
VSSolution = new VisualStudio.Solution();
VSSolution.Headers.Add(PackageSessionHelper.SolutionHeader);
VSSolution.Headers.Add(SolutionHeader);

Projects = new ProjectCollection();
Projects.CollectionChanged += ProjectsCollectionChanged;
@@ -706,6 +711,30 @@ private PackageContainer LoadProject(ILogger log, string filePath, bool isSystem
{
var project = Package.LoadProject(log, filePath);

// Upgrade from 3.0: figure out if this was the package project
var vsProject = VSSolution.Projects.FirstOrDefault(x => x.FullPath == filePath);
var vsPackage = vsProject?.GetParentProject(VSSolution);
if (vsPackage != null && PackageSessionHelper.IsPackage(vsPackage, out var packagePathRelative))
{
var packagePath = Path.Combine(Path.GetDirectoryName(VSSolution.FullPath), packagePathRelative);
if (File.Exists(packagePath))
{
var packageProject = Package.LoadProject(log, packagePath);
if ((packageProject as SolutionProject)?.FullPath == new UFile(filePath))
{
project = packageProject;

// Remove solution folder
foreach (var vsProject2 in VSSolution.Projects)
{
if (vsProject2.ParentGuid == vsPackage.Guid)
vsProject2.ParentGuid = Guid.Empty;
}
VSSolution.Projects.Remove(vsPackage);
}
}
}

var package = project.Package;
package.IsSystem = isSystem;

@@ -762,7 +791,7 @@ public static void Load(string filePath, PackageSessionResult sessionResult, Pac
SolutionProject firstProject = null;

// If we have a solution, load all packages
if (PackageSessionHelper.IsSolutionFile(filePath))
if (Path.GetExtension(filePath).ToLowerInvariant() == ".sln")
{
// The session should save back its changes to the solution
var solution = session.VSSolution = VisualStudio.Solution.FromFile(filePath);
@@ -775,7 +804,8 @@ public static void Load(string filePath, PackageSessionResult sessionResult, Pac
else
session.VisualStudioVersion = null;

foreach (var vsProject in solution.Projects)
// Note: using ToList() because upgrade from old package system might change Projects list
foreach (var vsProject in solution.Projects.ToList())
{
if (vsProject.TypeGuid == VisualStudio.KnownProjectTypeGuid.CSharp || vsProject.TypeGuid == VisualStudio.KnownProjectTypeGuid.CSharpNewSystem)
{
@@ -22,11 +22,6 @@ internal partial class PackageSessionHelper
private const string XenkoPackage = "XenkoPackage";
private static readonly string[] SolutionPackageIdentifier = new[] { XenkoPackage, "SiliconStudioPackage" };

public static bool IsSolutionFile(string filePath)
{
return String.Compare(Path.GetExtension(filePath), ".sln", StringComparison.InvariantCultureIgnoreCase) == 0;
}

public static async Task<PackageVersion> GetPackageVersion(string fullPath)
{
try

This file was deleted.

0 comments on commit c1904fc

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