Esempio n. 1
0
        /// <summary>
        /// This function retrieves the latest version information from the build file for a provided assembly.
        /// </summary>
        /// <param name="assemblyName">The name of the assembly.</param>
        /// <returns>The latest version information for the specified assembly from the build file. If the version information for the
        /// specified assembly is not present in the assembly build file, then the function returns null.</returns>
        public static Version GetLatestAssemblyVersion(string assemblyName)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }

            if (Versions == null)
            {
                Versions = VersionFileReader.GetVersions(AssemblyVersionsFile, AssemblyElementXPath);
                if (Versions == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, Resources.VersionsFileMissing, AssemblyVersionsFile));
                }
            }

            string assemblyVersion;

            Versions.TryGetValue(assemblyName, out assemblyVersion);

            Version version;

            if (!Version.TryParse(assemblyVersion, out version))
            {
                return(null);
            }

            return(version);
        }
Esempio n. 2
0
        /// <summary>
        /// This function retrieves the package versions from the package version file based on the project references.
        /// </summary>
        /// <param name="context">The <see cref="CodeGenerationContext"/> provided by core scaffolding.</param>
        /// <returns>A <see cref="Dictionary"/> containing package id as the key and version as the value.</returns>
        public static IDictionary <string, string> GetPackageVersions(CodeGenerationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IDictionary <string, string> packageVersions;

            string packageVersionsFile = GetPackageReferenceFileName(context);

            Contract.Assert(packageVersionsFile != null);

            // We are storing the computed package versions in the packageFileContents to avoid multiple calls to the file system.
            if (PackageFileContents == null)
            {
                PackageFileContents = new Dictionary <string, IDictionary <string, string> >(StringComparer.OrdinalIgnoreCase);
            }
            else
            {
                PackageFileContents.TryGetValue(packageVersionsFile, out packageVersions);

                if (packageVersions != null)
                {
                    return(packageVersions);
                }
            }

            packageVersions = VersionFileReader.GetVersions(packageVersionsFile, PackageElementXPath);
            if (packageVersions == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, Resources.VersionsFileMissing, packageVersionsFile));
            }

            PackageFileContents[packageVersionsFile] = packageVersions;
            return(packageVersions);
        }