Skip to content
Permalink
Browse files

[VSPackage] Fix NuGet assembly resolve (avoid infinite loop) and hand…

…le properly non-Xenko solutions (fixes #298)
  • Loading branch information
xen2 committed Dec 25, 2018
1 parent e2b7b27 commit 8e98e23c24e14c41deee8457c811055d6c2dec69
@@ -83,15 +83,20 @@ public static void InitializeFromSolution(string solutionPath, PackageInfo xenko
else
{
var initializationHelper = (InitializationHelper)domain.CreateInstanceFromAndUnwrap(typeof(InitializationHelper).Assembly.Location, typeof(InitializationHelper).FullName);
initializationHelper.Initialize(solutionPath, xenkoPackageInfo.SdkPaths, xenkoPackageInfo.ExpectedVersion.ToString(), xenkoPackageInfo.LoadedVersion.ToString());
initializationHelper.Initialize(solutionPath, xenkoPackageInfo.SdkPaths, xenkoPackageInfo.ExpectedVersion?.ToString(), xenkoPackageInfo.LoadedVersion?.ToString());
}
}

private class InitializationHelper : MarshalByRefObject
{
public void Initialize(string solutionPath, List<string> sdkPaths, string expectedVersion, string loadedVersion)
{
InitializeFromSolution(solutionPath, new PackageInfo { SdkPaths = sdkPaths, ExpectedVersion = new PackageVersion(expectedVersion), LoadedVersion = new PackageVersion(loadedVersion) });
InitializeFromSolution(solutionPath, new PackageInfo
{
SdkPaths = sdkPaths,
ExpectedVersion = expectedVersion != null ? new PackageVersion(expectedVersion) : null,
LoadedVersion = loadedVersion != null ? new PackageVersion(loadedVersion) : null,
});
}
}

@@ -135,9 +140,11 @@ public static XenkoCommandsProxy GetProxy()
}
}

currentAppDomain = CreateXenkoDomain();

var xenkoPackageInfo = FindXenkoSdkDir(solution).Result;
if (xenkoPackageInfo.LoadedVersion == null)
return null;

currentAppDomain = CreateXenkoDomain();
InitializeFromSolution(solution, xenkoPackageInfo, currentAppDomain);
currentInstance = CreateProxy(currentAppDomain);
currentInstance.Initialize();
@@ -225,17 +232,17 @@ private static Assembly DefaultDomainAssemblyResolve(object sender, ResolveEvent
if (assemblyName.Name == executingAssembly.GetName().Name)
return executingAssembly;

// Necessary to avoid conflicts with Visual Studio NuGet
if (args.Name.StartsWith("NuGet", StringComparison.InvariantCultureIgnoreCase))
return Assembly.Load(assemblyName);

return null;
}

private Assembly XenkoDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
var assemblyName = new AssemblyName(args.Name);

// Necessary to avoid conflicts with Visual Studio NuGet
if (args.Name.StartsWith("NuGet", StringComparison.InvariantCultureIgnoreCase))
return Assembly.Load(assemblyName);

var assemblyPath = computedPackageInfo.SdkPaths.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == assemblyName.Name);
if (assemblyPath != null)
{
@@ -298,7 +298,7 @@ public RawShaderNavigationResult AnalyzeAndGoToDefinition(string text, RawSource
{
projectFile = projectItem.ContainingProject.FileName;
}
return XenkoCommandsProxy.GetProxy().AnalyzeAndGoToDefinition(projectFile, text, span);
return XenkoCommandsProxy.GetProxy()?.AnalyzeAndGoToDefinition(projectFile, text, span) ?? new RawShaderNavigationResult();
}

private NShaderSource GetCurrentNShaderSource()
@@ -82,6 +82,8 @@ private void AnalyzeAndGoToDefinition()
try
{
var remoteCommands = XenkoCommandsProxy.GetProxy();
if (remoteCommands == null)
return;
var location = new RawSourceSpan()
{
File = this.Source.GetFilePath(),
@@ -17,7 +17,7 @@
<XenkoAssemblyProcessor>false</XenkoAssemblyProcessor>
<XenkoBuildTags>WindowsTools</XenkoBuildTags>
<XenkoSkipAutoPack>true</XenkoSkipAutoPack>
<PackageVersion>3.0.1</PackageVersion>
<PackageVersion>3.0.2</PackageVersion>
<VSSDKTargetPlatformRegRootSuffix>Xenko</VSSDKTargetPlatformRegRootSuffix>
</PropertyGroup>
<ItemGroup>
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>Xenko.VisualStudio.Package</id>
<version>3.0.1</version>
<version>3.0.2</version>
<authors>Xenko</authors>
<owners>Xenko</owners>
<licenseUrl>http://xenko.com/license.txt</licenseUrl>
@@ -308,6 +308,8 @@ private async System.Threading.Tasks.Task InitializeCommandProxy()
var solutionPath = dte.Solution.FullName;

var xenkoPackageInfo = await XenkoCommandsProxy.FindXenkoSdkDir(solutionPath);
if (xenkoPackageInfo.LoadedVersion == null)
return;
XenkoCommandsProxy.InitializeFromSolution(solutionPath, xenkoPackageInfo);

// Get General Output pane (for error logging)

0 comments on commit 8e98e23

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