Skip to content
Permalink
Browse files

[Assets] Ignore assets from executable projects (computed automatically)

  • Loading branch information
xen2 committed Sep 11, 2018
1 parent ab92536 commit 64c251e6435eacc476bdb79f744877386ec9ed72
@@ -1143,56 +1143,56 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters
if (loadParameters == null) throw new ArgumentNullException(nameof(loadParameters));
var assemblyContainer = loadParameters.AssemblyContainer ?? AssemblyContainer.Default;

var projectFullPath = (Container as SolutionProject)?.FullPath;
if (projectFullPath != null)
{
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, projectFullPath, Core.Assets.ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;
var project = Container as SolutionProject;
if (project == null || project.FullPath == null || project.Type != ProjectType.Library)
return;

string assemblyPath = null;
var fullProjectLocation = projectFullPath.ToWindowsPath();
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, project.FullPath, Core.Assets.ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;

try
string assemblyPath = null;
var fullProjectLocation = project.FullPath.ToWindowsPath();

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}]");
return;
}
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}]");
return;
}
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);
}
}

/// <summary>
@@ -1379,18 +1379,18 @@ private static void FindAssetsInProject(ICollection<PackageLoadingAssetFile> lis
{
if (package.IsSystem) return;

var projectFullPath = (package.Container as SolutionProject)?.FullPath;
if (projectFullPath != null)
{
string defaultNamespace;
var codePaths = FindAssetsInProject(projectFullPath, out defaultNamespace);
package.RootNamespace = defaultNamespace;
var dir = new UDirectory(projectFullPath.GetFullDirectory());
var project = package.Container as SolutionProject;
if (project == null || project.FullPath == null || project.Type != ProjectType.Library)
return;

foreach (var codePath in codePaths)
{
list.Add(new PackageLoadingAssetFile(codePath, dir));
}
string defaultNamespace;
var codePaths = FindAssetsInProject(project.FullPath, out defaultNamespace);
package.RootNamespace = defaultNamespace;
var dir = new UDirectory(project.FullPath.GetFullDirectory());

foreach (var codePath in codePaths)
{
list.Add(new PackageLoadingAssetFile(codePath, dir));
}
}

@@ -251,6 +251,30 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
project.LoadedDependencies.Add(loadedPackage);
}

// Load some informations about the project
try
{
// Load a project without specifying a platform to make sure we get the correct platform type
var msProject = VSProjectHelper.LoadProject(project.FullPath, platform: "NoPlatform");
try
{

var projectIsExecutable = msProject.GetPropertyValue("XenkoIsExecutable");
project.Type = projectIsExecutable.ToLowerInvariant() == "true" ? ProjectType.Executable : ProjectType.Library;
if (project.Type == ProjectType.Executable)
project.Platform = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;
}
finally
{
msProject.ProjectCollection.UnloadAllProjects();
msProject.ProjectCollection.Dispose();
}
}
catch (Exception ex)
{
log.Error($"Unexpected exception while loading project [{project.FullPath.ToWindowsPath()}]", ex);
}

// 2. Load local packages
/*foreach (var packageReference in package.LocalDependencies)
{

0 comments on commit 64c251e

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