コード例 #1
0
        /// <summary>
        /// edits certain project based values for c# and visual studio projects
        /// </summary>
        /// <param name="activeProject">the active project that is to be deployed</param>
        /// <param name="project">project configuration to use</param>
        /// <returns>null if all edits were down, otherwise the error string</returns>
        private void ChangeNuSpec(Project activeProject, PackageInformation packageInfo)
        {
            LoggingManager.Instance.Logger.Debug("changing project started");

            //-----edit values here
            if (!string.IsNullOrEmpty(packageInfo.NuSpecPackage.Metadata.Version) && packageInfo.ProjectOptions.GeneralOptions.VersionComponent.HasValue)
            {
                LoggingManager.Instance.Logger.Debug(string.Format("changing version [{0}]", packageInfo.NuSpecPackage.Metadata.Version));

                HashSet <VersionComponentInfo> version = VersionUtil.GetVersion(packageInfo.NuSpecPackage.Metadata.Version, null, packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionInformationalSeparator);

                VersionUtil.IncreaseVersion(version, packageInfo.ProjectOptions.GeneralOptions.VersionComponent.Value, null, packageInfo.ProjectOptions.GeneralOptions.HandleIncrementOverflow);

                packageInfo.NuSpecPackage.Metadata.Version = VersionUtil.CreateVersion(version, null, packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionInformationalSeparator);

                LoggingManager.Instance.Logger.Debug(string.Format("new version [{0}]", packageInfo.NuSpecPackage.Metadata.Version));
            }

            LoggingManager.Instance.Logger.Debug("changing project finished");
        }
コード例 #2
0
ファイル: SaveWorker.cs プロジェクト: wirblaxe/NuGetDeploy
        /// <summary>
        /// callback to be invoked when a line is to be read and written back to the assembly info of a c++ project
        /// </summary>
        /// <param name="line">line that has been read</param>
        /// <param name="objs">object containing the deployment info and the Configuration project</param>
        /// <returns>new line to be written</returns>
        private string AssemblyInfoReadCallback(string line, object[] objs)
        {
            PackageInformation packageInfo        = (PackageInformation)objs[0];
            ProjectInformation projectInformation = (ProjectInformation)objs[1];

            LoggingManager.Instance.Logger.Debug(string.Format("changing line: {0}", line));

            int index = line.IndexOf(projectInformation.AssemblyInfoIdentifier);

            if (index != -1)
            {
                string lineContent = line.Substring(projectInformation.AssemblyInfoIdentifier.Length, line.Length - projectInformation.AssemblyInfoIdentifier.Length).Trim();

                bool hasContent = false;

                string content = null;

                if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Version.Save &&
                    (lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyVersion],
                                                            Definitions.Constants.AssemblyContentStart)) ||
                     lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyVersion],
                                                            Definitions.Constants.AssemblyAttributeAddition,
                                                            Definitions.Constants.AssemblyContentStart)) ||
                     lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyFileVersion],
                                                            Definitions.Constants.AssemblyContentStart)) ||
                     lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyFileVersion],
                                                            Definitions.Constants.AssemblyAttributeAddition,
                                                            Definitions.Constants.AssemblyContentStart)) ||
                     lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyInformationalVersion],
                                                            Definitions.Constants.AssemblyContentStart)) ||
                     lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyInformationalVersion],
                                                            Definitions.Constants.AssemblyAttributeAddition,
                                                            Definitions.Constants.AssemblyContentStart))))
                {
                    string version = VersionUtil.CreateVersion(VersionUtil.GetVersion(packageInfo.NuSpecPackage.Metadata.Version), VersionUtil.VersionComponentOrderWithOutInformational);

                    string versionWithInformational = VersionUtil.CreateVersion(VersionUtil.GetVersion(packageInfo.NuSpecPackage.Metadata.Version),
                                                                                null,
                                                                                packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionInformationalSeparator);

                    string versionToUse = version;

                    if (packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionIdentifier == AssemblyVersionIdentifier.AssemblyInformationalVersion)
                    {
                        versionToUse = versionWithInformational;
                    }

                    if (packageInfo.ProjectOptions.GeneralOptions.SaveBackVersionInAllIdentifiers &&
                        (lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyVersion],
                                                                Definitions.Constants.AssemblyContentStart)) ||
                         lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyVersion],
                                                                Definitions.Constants.AssemblyAttributeAddition,
                                                                Definitions.Constants.AssemblyContentStart))))
                    {
                        content    = version;
                        hasContent = true;
                    }
                    if (packageInfo.ProjectOptions.GeneralOptions.SaveBackVersionInAllIdentifiers &&
                        (lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyFileVersion],
                                                                Definitions.Constants.AssemblyContentStart)) ||
                         lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyFileVersion],
                                                                Definitions.Constants.AssemblyAttributeAddition,
                                                                Definitions.Constants.AssemblyContentStart))))
                    {
                        content    = version;
                        hasContent = true;
                    }
                    if (packageInfo.ProjectOptions.GeneralOptions.SaveBackVersionInAllIdentifiers &&
                        (lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyInformationalVersion],
                                                                Definitions.Constants.AssemblyContentStart)) ||
                         lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[AssemblyVersionIdentifier.AssemblyInformationalVersion],
                                                                Definitions.Constants.AssemblyAttributeAddition,
                                                                Definitions.Constants.AssemblyContentStart))))
                    {
                        content    = versionWithInformational;
                        hasContent = true;
                    }
                    else if (lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionIdentifier],
                                                                    Definitions.Constants.AssemblyContentStart)) ||
                             lineContent.StartsWith(StringUtil.Join(Definitions.Constants.AssemblyInfoVersionIdentifierNames[packageInfo.ProjectOptions.GeneralOptions.AssemblyInfoVersionIdentifier],
                                                                    Definitions.Constants.AssemblyAttributeAddition,
                                                                    Definitions.Constants.AssemblyContentStart)))
                    {
                        content    = versionToUse;
                        hasContent = true;
                    }
                }
                else if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Title.Save &&
                         (lineContent.StartsWith(StringUtil.Join(projectInformation.Title,
                                                                 Definitions.Constants.AssemblyContentStart)) ||
                          lineContent.StartsWith(StringUtil.Join(projectInformation.Title,
                                                                 Definitions.Constants.AssemblyAttributeAddition,
                                                                 Definitions.Constants.AssemblyContentStart))))
                {
                    content    = packageInfo.NuSpecPackage.Metadata.Title;
                    hasContent = true;
                }
                else if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Authors.Save &&
                         (lineContent.StartsWith(StringUtil.Join(projectInformation.Authors,
                                                                 Definitions.Constants.AssemblyContentStart)) ||
                          lineContent.StartsWith(StringUtil.Join(projectInformation.Authors,
                                                                 Definitions.Constants.AssemblyAttributeAddition,
                                                                 Definitions.Constants.AssemblyContentStart))))
                {
                    content    = packageInfo.NuSpecPackage.Metadata.Authors;
                    hasContent = true;
                }
                else if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Description.Save &&
                         (lineContent.StartsWith(StringUtil.Join(projectInformation.Description,
                                                                 Definitions.Constants.AssemblyContentStart)) ||
                          lineContent.StartsWith(StringUtil.Join(projectInformation.Description,
                                                                 Definitions.Constants.AssemblyAttributeAddition,
                                                                 Definitions.Constants.AssemblyContentStart))))
                {
                    content    = packageInfo.NuSpecPackage.Metadata.Description;
                    hasContent = true;
                }
                else if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Language.Save &&
                         (lineContent.StartsWith(StringUtil.Join(projectInformation.Language,
                                                                 Definitions.Constants.AssemblyContentStart)) ||
                          lineContent.StartsWith(StringUtil.Join(projectInformation.Language,
                                                                 Definitions.Constants.AssemblyAttributeAddition,
                                                                 Definitions.Constants.AssemblyContentStart))))
                {
                    content    = packageInfo.NuSpecPackage.Metadata.Language;
                    hasContent = true;
                }
                else if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.Copyright.Save &&
                         (lineContent.StartsWith(StringUtil.Join(projectInformation.Copyright,
                                                                 Definitions.Constants.AssemblyContentStart)) ||
                          lineContent.StartsWith(StringUtil.Join(projectInformation.Copyright,
                                                                 Definitions.Constants.AssemblyAttributeAddition,
                                                                 Definitions.Constants.AssemblyContentStart))))
                {
                    content    = packageInfo.NuSpecPackage.Metadata.Copyright;
                    hasContent = true;
                }

                //use the content we created here
                if (hasContent)
                {
                    return(string.Format("{0}{1}{2}",
                                         StringUtil.Substring(line, 0, line.IndexOf(Definitions.Constants.AssemblyContentStart) + Definitions.Constants.AssemblyContentStart.Length - 1),
                                         content,
                                         StringUtil.Substring(line, line.LastIndexOf(Definitions.Constants.AssemblyContentEnd), line.Length - 1)));
                }

                return(line);
            }
            else
            {
                return(line);
            }
        }