Exemplo n.º 1
0
        /// <summary>
        /// Gets the stride SDK dir.
        /// </summary>
        /// <returns></returns>
        internal static async Task <PackageInfo> FindStrideSdkDir(string solution, string packageName = "Stride.VisualStudio.Commands")
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = await PackageSessionHelper.GetPackageVersion(solution), SdkPaths = new List <string>()
            };

            // Try to find the package with the expected version
            if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
            {
                // Try both net5.0 and net472
                var success = false;
                foreach (var framework in new[] { ".NET,Version=v5.0", ".NETFramework,Version=v4.7.2" })
                {
                    var logger       = new Logger();
                    var solutionRoot = Path.GetDirectoryName(solution);
                    var(request, result) = await Task.Run(() => RestoreHelper.Restore(logger, NuGetFramework.ParseFrameworkName(framework, DefaultFrameworkNameProvider.Instance), "win", packageName, new VersionRange(packageInfo.ExpectedVersion.ToNuGetVersion()), solutionRoot));

                    if (result.Success)
                    {
                        packageInfo.SdkPaths.AddRange(RestoreHelper.ListAssemblies(result.LockFile));
                        packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                        success = true;
                        break;
                    }
                }
                if (!success)
                {
                    throw new InvalidOperationException($"Could not restore {packageName} {packageInfo.ExpectedVersion}, this visual studio extension may fail to work properly without it. To fix this you can either build {packageName} or pull the right version from nugget manually");
                }
            }

            return(packageInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <returns></returns>
        internal static async Task <PackageInfo> FindXenkoSdkDir(string solution, string packageName = "Xenko.VisualStudio.Commands")
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = await PackageSessionHelper.GetPackageVersion(solution), SdkPaths = new List <string>()
            };

            // Check if we are in a root directory with store/packages facilities
            var store = new NugetStore(null);
            NugetLocalPackage xenkoPackage = null;

            // Try to find the package with the expected version
            if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
            {
                // Xenko up to 3.0
                if (packageInfo.ExpectedVersion < new PackageVersion(3, 1, 0, 0))
                {
                    xenkoPackage = store.GetPackagesInstalled(new[] { "Xenko" }).FirstOrDefault(package => package.Version == packageInfo.ExpectedVersion);
                    if (xenkoPackage != null)
                    {
                        var xenkoSdkDir = store.GetRealPath(xenkoPackage);

                        packageInfo.LoadedVersion = xenkoPackage.Version;

                        foreach (var path in new[]
                        {
                            // Xenko 2.x and 3.0
                            @"Bin\Windows\Direct3D11",
                            @"Bin\Windows",
                            // Xenko 1.x
                            @"Bin\Windows-Direct3D11"
                        })
                        {
                            var fullPath = Path.Combine(xenkoSdkDir, path);
                            if (Directory.Exists(fullPath))
                            {
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.TopDirectoryOnly));
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.exe", SearchOption.TopDirectoryOnly));
                            }
                        }
                    }
                }
                // Xenko 3.1+
                else
                {
                    var logger = new Logger();
                    var(request, result) = await RestoreHelper.Restore(logger, packageName, new VersionRange(packageInfo.ExpectedVersion.ToNuGetVersion()));

                    if (result.Success)
                    {
                        packageInfo.SdkPaths.AddRange(RestoreHelper.ListAssemblies(request, result));
                        packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                    }
                }
            }

            return(packageInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <returns></returns>
        private static PackageInfo FindXenkoSdkDir()
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = PackageSessionHelper.GetPackageVersion(solution)
            };

            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var xenkoSdkDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir");

            // Failed to locate xenko
            if (xenkoSdkDir == null)
            {
                return(packageInfo);
            }

            // If we are in a dev directory, assume we have the right version
            if (File.Exists(Path.Combine(xenkoSdkDir, "build\\Xenko.sln")))
            {
                packageInfo.SdkPath       = xenkoSdkDir;
                packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                return(packageInfo);
            }

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(xenkoSdkDir))
            {
                var      store        = new NugetStore(xenkoSdkDir);
                IPackage xenkoPackage = null;

                // Try to find the package with the expected version
                if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
                {
                    xenkoPackage = store.GetPackagesInstalled(store.MainPackageIds).FirstOrDefault(package => GetVersion(package) == packageInfo.ExpectedVersion);
                }

                // If the expected version is not found, get the latest package
                if (xenkoPackage == null)
                {
                    xenkoPackage = store.GetLatestPackageInstalled(store.MainPackageIds);
                }

                // If no package was found, return no sdk path
                if (xenkoPackage == null)
                {
                    return(packageInfo);
                }

                // Return the loaded version and the sdk path
                var packageDirectory = store.PathResolver.GetPackageDirectory(xenkoPackage);
                packageInfo.LoadedVersion = GetVersion(xenkoPackage);
                packageInfo.SdkPath       = Path.Combine(xenkoSdkDir, store.RepositoryPath, packageDirectory);
            }

            return(packageInfo);
        }
Exemplo n.º 4
0
        private void DiscoverXenkoVersion()
        {
            Task.Run(() =>
            {
                XenkoVersion     = PackageSessionHelper.GetPackageVersion(fullPath);
                XenkoVersionName = XenkoVersion?.ToString();

                Dispatcher.Invoke(() => OpenCommand.IsEnabled = XenkoVersionName != null);
            });
        }
Exemplo n.º 5
0
        private void DiscoverStrideVersion()
        {
            Task.Run(async() =>
            {
                var packageVersion = await PackageSessionHelper.GetPackageVersion(fullPath);
                StrideVersion      = packageVersion != null ? new Version(packageVersion.Version.Major, packageVersion.Version.Minor) : null;
                StrideVersionName  = StrideVersion?.ToString();

                Dispatcher.Invoke(() => OpenCommand.IsEnabled = StrideVersionName != null);
            });
        }
Exemplo n.º 6
0
        public void RemoveRecentFile(UFile filePath)
        {
            var packageVersion = PackageSessionHelper.GetPackageVersion(filePath);

            //Remove considering old projects that have been deleted or upgraded from older versions
            if (packageVersion == null || string.Compare(packageVersion.ToString(), "3.0", StringComparison.Ordinal) <= 0)
            {
                //Get all versions of showing on recent files
                var xenkoVersions = RecentFiles?.Select(x => x.Version).ToList();
                if (xenkoVersions != null)
                {
                    foreach (var item in xenkoVersions)
                    {
                        MRU.RemoveFile(filePath, item);
                    }
                }
            }
            else
            {
                MRU.RemoveFile(filePath, packageVersion.ToString());
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the stride SDK dir.
        /// </summary>
        /// <returns></returns>
        internal static async Task <PackageInfo> FindStrideSdkDir(string solution, string packageName = "Stride.VisualStudio.Commands")
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = await PackageSessionHelper.GetPackageVersion(solution), SdkPaths = new List <string>()
            };

            // Check if we are in a root directory with store/packages facilities
            var store = new NugetStore(null);
            NugetLocalPackage stridePackage = null;

            // Try to find the package with the expected version
            if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
            {
                // Stride up to 3.0
                if (packageInfo.ExpectedVersion < new PackageVersion(3, 1, 0, 0))
                {
                    stridePackage = store.GetPackagesInstalled(new[] { "Stride" }).FirstOrDefault(package => package.Version == packageInfo.ExpectedVersion);
                    if (stridePackage != null)
                    {
                        var strideSdkDir = store.GetRealPath(stridePackage);

                        packageInfo.LoadedVersion = stridePackage.Version;

                        foreach (var path in new[]
                        {
                            // Stride 2.x and 3.0
                            @"Bin\Windows\Direct3D11",
                            @"Bin\Windows",
                            // Stride 1.x
                            @"Bin\Windows-Direct3D11"
                        })
                        {
                            var fullPath = Path.Combine(strideSdkDir, path);
                            if (Directory.Exists(fullPath))
                            {
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.TopDirectoryOnly));
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.exe", SearchOption.TopDirectoryOnly));
                            }
                        }
                    }
                }
                // Stride 3.1+
                else
                {
                    var logger = new Logger();
                    var(request, result) = await RestoreHelper.Restore(logger, NuGetFramework.ParseFrameworkName(".NETFramework,Version=v4.7.2", DefaultFrameworkNameProvider.Instance), "win", packageName, new VersionRange(packageInfo.ExpectedVersion.ToNuGetVersion()));

                    if (result.Success)
                    {
                        packageInfo.SdkPaths.AddRange(RestoreHelper.ListAssemblies(request, result));
                        packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                    }
                    else
                    {
                        MessageBox.Show($"Could not restore {packageName} {packageInfo.ExpectedVersion}, this visual studio extension may fail to work properly without it."
                                        + $"To fix this you can either build {packageName} or pull the right version from nugget manually");
                        throw new InvalidOperationException($"Could not restore {packageName} {packageInfo.ExpectedVersion}.");
                    }
                }
            }

            return(packageInfo);
        }