示例#1
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <param name="xenkoVersion">The xenko version. If null, it will get latest version.</param>
        /// <returns></returns>
        public static string FindXenkoSdkDir(string xenkoVersion = null)
        {
            // TODO: Almost duplicate of XenkoCommandsProxy.FindXenkoSdkDir!!
            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var xenkoSdkDir = DirectoryHelper.GetInstallationDirectory("Xenko");

            if (xenkoSdkDir == null)
            {
                xenkoSdkDir = Environment.GetEnvironmentVariable("XenkoDir");
            }

            if (xenkoSdkDir == null)
            {
                return(null);
            }

            // Check if it is a dev directory
            if (DirectoryHelper.IsRootDevDirectory(xenkoSdkDir))
            {
                return(xenkoSdkDir);
            }

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

            var xenkoPackages = store.GetPackagesInstalled(store.MainPackageIds);

            // Convert the provided xenko version into a valid package version
            PackageVersion.TryParse(xenkoVersion, out var packageVersion);
            // Retrieve the corresponding package, if it exists
            var xenkoPackage = packageVersion != null
                ? (xenkoPackages.FirstOrDefault(p => p.Version == packageVersion)
                   ?? xenkoPackages.FirstOrDefault(p => p.Version.Version == packageVersion.Version))  // If no exact match, try a second time without the special version tag (beta, alpha, etc...)
                : xenkoPackages.FirstOrDefault();

            if (xenkoPackage == null)
            {
                return(null);
            }

            var packageDirectory = store.GetInstalledPath(xenkoPackage.Id, xenkoPackage.Version);

            return(packageDirectory);
        }