/// <summary> /// In comments below this method is a method that will attempt to load the /// .nuspec file as an XDocument and process it as such. This seems to be a /// bit of overkill in that MS has very nicely included a default .nuspec /// file if the nuget "spec" command is executed in the same directory as /// the target .csproj file. Since this is the case AND said .nuspec file /// contains replaceable tokens, it's really easier to simply load the /// entire file into a StringBuilder, replace the desired tokens with the /// established values and then write the thing back out to the drive, thus /// this method. /// </summary> private void ProcessFullFrameworkNuSpecFileForPack() { const StringComparison COMPARISON = StringComparison.InvariantCultureIgnoreCase; NoOp = !File.Exists(NuSpecFilePath) || NoOp; if (NoOp) { return; } string vPath = NuSpecFilePath; StringBuilder vContent = new StringBuilder(File.ReadAllText(vPath)); int vChangeCount = 0; string vLookFor; if (_HandleConfiguration.NuGetNuSpecSettings.ForceAuthors) { vLookFor = AUTHOR_KEY + AUTHORS.AsToken(); vContent.Replace ( vLookFor , AUTHOR_KEY + _HandleConfiguration.NuGetNuSpecSettings.Authors ); vChangeCount++; } if (_HandleConfiguration.NuGetNuSpecSettings.ForceCopyright) { vLookFor = $"{COPYRIGHT} {DateTime.Now.Year}"; vContent.Replace ( vLookFor.AsToken() , _HandleConfiguration.NuGetNuSpecSettings.Copyright ); vChangeCount++; } vLookFor = DESCRIPTION.AsToken(); if (_HandleConfiguration.NuGetNuSpecSettings.ForceDescription) { vContent.Replace ( vLookFor.AsToken() , _HandleConfiguration.NuGetNuSpecSettings.Description ); vChangeCount++; } else { string vFind = DESCRIPTION_KEY_START + DEFAULT_DESCRIPTION + DESCRIPTION_KEY_END + "\r\n"; string vReplaceWith = DESCRIPTION_KEY_START + DEFAULT_DESCRIPTION + DateTime.Now.ToLongDateString() + DESCRIPTION_KEY_END + "\r\n"; vContent.Replace(vFind, vReplaceWith); vChangeCount++; } vLookFor = ICON_URL_KEY + ICON_URL_OR_DELETE_THIS; if (_HandleConfiguration.NuGetNuSpecSettings.ForceIconUrl) { vContent.Replace (vLookFor, _HandleConfiguration.NuGetNuSpecSettings.IconUrl); vChangeCount++; } else { string vFind = ICON_URL_KEY + ICON_URL_OR_DELETE_THIS + ICON_URL_KEY_END + "\r\n"; vContent.Replace(vFind, String.Empty); vChangeCount++; } vLookFor = LICENSE_URL; if (_HandleConfiguration.NuGetNuSpecSettings.ForceLicenseUrl) { vContent.Replace ( vLookFor.AsToken(), _HandleConfiguration.NuGetNuSpecSettings.LicenseUrl ); vChangeCount++; } else { string vFind = LICENSE_URL_KEY + LICENSE_URL_OR_DELETE_THIS + LICENSE_URL_KEY_END + "\r\n"; vContent.Replace(vFind, String.Empty); vChangeCount++; } vLookFor = PROJECT_URL; if (_HandleConfiguration.NuGetNuSpecSettings.ForceProjectUrl) { vContent.Replace ( vLookFor.AsToken(), _HandleConfiguration.NuGetNuSpecSettings.ProjectUrl ); vChangeCount++; } else { string vFind = PROJECT_URL_KEY + PROJECT_URL_OR_DELETE_THIS + PROJECT_URL_KEY_END + "\r\n"; vContent.Replace(vFind, String.Empty); vChangeCount++; } if (_HandleConfiguration.NuGetNuSpecSettings.ForceOwners) { vLookFor = OWNER_KEY + AUTHORS.AsToken(); vContent.Replace ( vLookFor , OWNER_KEY + _HandleConfiguration.NuGetNuSpecSettings.Owners ); vChangeCount++; } vLookFor = DEFAULT_RELEASE_NOTES; if (_HandleConfiguration.NuGetNuSpecSettings.ForceReleaseNotes) { if (_HandleConfiguration.AppSettingsValues.RequireReleaseNotesFile) { vContent.Replace(vLookFor, ExtractReleaseNotes()); vChangeCount++; } } else { string vFind = RELEASE_NOTES_KEY + DEFAULT_RELEASE_NOTES + RELEASE_NOTES_KEY_END + "\r\n"; vContent.Replace(vFind, String.Empty); vChangeCount++; } if (_HandleConfiguration.NuGetNuSpecSettings.ForceRequireLicenseAcceptance) { vLookFor = REQUIRE_LICENSE_ACCEPTANCE_KEY + DEFAULT_REQUIRE_LICENSE_ACCEPTANCE; vContent.Replace ( vLookFor, _HandleConfiguration.NuGetNuSpecSettings.RequireLicenseAcceptance ); vChangeCount++; } if (_HandleConfiguration.AppSettingsValues.RequireSummaryFile) { vLookFor = SUMMARY_KEY; string vContentAsString = vContent.ToString(); int vIndex = vContentAsString.IndexOf(vLookFor, COMPARISON); if (vIndex < 0) { vIndex = vContentAsString.IndexOf (METADATA_END, COMPARISON); string vNewKey = SUMMARY_KEY + ExtractNuGetSummary() + SUMMARY_KEY_END; vContent.Insert(vIndex, vNewKey); vChangeCount++; } else { // This shouldn't ever have to be executed, but just in case MS // changes how nuget.exe functions... int vEndIndex = vContentAsString.IndexOf (SUMMARY_KEY_END, COMPARISON); vIndex = vIndex + SUMMARY_KEY.Length; int vHowMuch = vEndIndex - vIndex + 1; vContentAsString = vContentAsString.Remove(vIndex, vHowMuch); vContentAsString = vContentAsString.Insert(vIndex, ExtractNuGetSummary()); vContent.Clear(); vContent.Append(vContentAsString); vChangeCount++; } } vLookFor = DEFAULT_TAGS; if (_HandleConfiguration.NuGetNuSpecSettings.ForceTags) { vContent.Replace(vLookFor, _HandleConfiguration.NuGetNuSpecSettings.Tags); vChangeCount++; } else { string vFind = TAGS_KEY_START + DEFAULT_TAGS + TAGS_KEY_END + "\r\n"; vContent.Replace(vFind, String.Empty); vChangeCount++; } if (_HandleConfiguration.NuGetNuSpecSettings.ForceTitle) { vLookFor = TITLE.AsToken(); vContent.Replace (vLookFor, _HandleConfiguration.NuGetNuSpecSettings.Title); vChangeCount++; } if (_HandleConfiguration.AppSettingsValues.ForceVersionOverride) { vLookFor = DotNetCSProjKeys.VERSION; vContent.Replace (vLookFor, _HandleConfiguration.AppSettingsValues.VersionOverride); vChangeCount++; } if (vChangeCount > 0) { File.WriteAllText(vPath, vContent.ToString()); } }
public override int GetHashCode() => DESCRIPTION?.GetHashCode() ?? 0;