本文整理汇总了C#中System.Xml.Linq.XContainer.ElementAnyNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XContainer.ElementAnyNamespace方法的具体用法?C# XContainer.ElementAnyNamespace怎么用?C# XContainer.ElementAnyNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XContainer
的用法示例。
在下文中一共展示了XContainer.ElementAnyNamespace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddReleaseNotes
private void AddReleaseNotes(XContainer nuSpec)
{
if (string.IsNullOrWhiteSpace(ReleaseNotesFile))
{
return;
}
ReleaseNotesFile = fileSystem.GetFullPath(ReleaseNotesFile);
if (!fileSystem.FileExists(ReleaseNotesFile))
{
LogWarning("OCT901", string.Format("The release notes file: {0} does not exist or could not be found. Release notes will not be added to the package.", ReleaseNotesFile));
return;
}
LogMessage("Adding release notes from file: " + ReleaseNotesFile);
var notes = fileSystem.ReadFile(ReleaseNotesFile);
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
var metadata = package.ElementAnyNamespace("metadata");
if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
var releaseNotes = metadata.ElementAnyNamespace("releaseNotes");
if (releaseNotes == null)
{
metadata.Add(new XElement("releaseNotes", notes));
}
else
{
releaseNotes.Value = notes;
}
}
示例2: AddFiles
private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
{
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
var files = package.ElementAnyNamespace("files");
if (files == null)
{
files = new XElement("files");
package.Add(files);
}
if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
{
relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
}
foreach (var sourceFile in sourceFiles)
{
var destinationPath = sourceFile.ItemSpec;
var link = sourceFile.GetMetadata("Link");
if (!string.IsNullOrWhiteSpace(link))
{
destinationPath = link;
}
if (Path.IsPathRooted(destinationPath))
{
destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
}
if (!string.IsNullOrWhiteSpace(relativeTo))
{
if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
{
destinationPath = destinationPath.Substring(relativeTo.Length);
}
}
destinationPath = Path.Combine(targetDirectory, destinationPath);
var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);
sourceFilePath = Path.GetFullPath(sourceFilePath);
if (!fileSystem.FileExists(sourceFilePath))
{
LogMessage("The source file '" + sourceFilePath + "' does not exist, so it will not be included in the package", MessageImportance.High);
continue;
}
if (seenBefore.Contains(sourceFilePath))
{
continue;
}
seenBefore.Add(sourceFilePath);
var fileName = Path.GetFileName(destinationPath);
if (string.Equals(fileName, "app.config", StringComparison.OrdinalIgnoreCase))
{
if (fileSystem.FileExists(AppConfigFile))
{
var configFileName = Path.GetFileName(AppConfigFile);
destinationPath = Path.GetDirectoryName(destinationPath);
destinationPath = Path.Combine(destinationPath, configFileName);
files.Add(new XElement("file",
new XAttribute("src", AppConfigFile),
new XAttribute("target", destinationPath)
));
LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
}
continue;
}
if (new[] {"Deploy.ps1", "DeployFailed.ps1", "PreDeploy.ps1", "PostDeploy.ps1"}.Any(f => string.Equals(f, fileName, StringComparison.OrdinalIgnoreCase)))
{
var isNonRoot = destinationPath.Contains('\\') || destinationPath.Contains('/');
if (isNonRoot && !IgnoreNonRootScripts)
{
LogWarning("OCTNONROOT", "As of Octopus Deploy 2.4, PowerShell scripts that are not at the root of the package will not be executed. The script '" + destinationPath + "' lives in a subdirectory, so it will not be executed. If you want Octopus to execute this script, move it to the root of your project. If you don't want it to be executed, you can ignore this warning, or suppress it by setting the MSBuild property OctoPackIgnoreNonRootScripts=true");
}
}
var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
if (isTypeScript)
{
if (IncludeTypeScriptSourceFiles)
{
files.Add(new XElement("file",
new XAttribute("src", sourceFilePath),
new XAttribute("target", destinationPath)
));
LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
}
var changedSource = Path.ChangeExtension(sourceFilePath, ".js");
var changedDestination = Path.ChangeExtension(destinationPath, ".js");
//.........这里部分代码省略.........
示例3: GetVersionElementFromNuSpec
private static XElement GetVersionElementFromNuSpec(XContainer nuSpec)
{
var package = nuSpec.ElementAnyNamespace("package");
if (package == null)
throw new Exception(
"The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
var metadata = package.ElementAnyNamespace("metadata");
if (metadata == null)
throw new Exception(
"The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid.");
var version = metadata.ElementAnyNamespace("version");
if (version == null)
throw new Exception(
"The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid.");
return version;
}
示例4: AddFiles
private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "")
{
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
var files = package.ElementAnyNamespace("files");
if (files == null)
{
files = new XElement("files");
package.Add(files);
}
foreach (var sourceFile in sourceFiles)
{
var destinationPath = sourceFile.ItemSpec;
var link = sourceFile.GetMetadata("Link");
if (!string.IsNullOrWhiteSpace(link))
{
destinationPath = link;
}
if (Path.IsPathRooted(destinationPath))
{
destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
}
destinationPath = Path.Combine(targetDirectory, destinationPath);
var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);
LogMessage("Including file: " + sourceFile, MessageImportance.Normal);
files.Add(new XElement("file",
new XAttribute("src", Path.GetFullPath(sourceFilePath)),
new XAttribute("target", destinationPath)
));
}
}
示例5: UpdatePackageIdWithAppendValue
private void UpdatePackageIdWithAppendValue(XContainer nuSpec)
{
if (string.IsNullOrWhiteSpace(AppendToPackageId))
{
return;
}
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
var metadata = package.ElementAnyNamespace("metadata");
if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
var packageId = metadata.ElementAnyNamespace("id");
if (packageId == null) throw new Exception(string.Format("The NuSpec file does not contain a <id> XML element. The NuSpec file appears to be invalid."));
packageId.Value = string.Format("{0}.{1}", packageId.Value, AppendToPackageId.Trim());
}
示例6: AddFiles
private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
{
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
var files = package.ElementAnyNamespace("files");
if (files == null)
{
files = new XElement("files");
package.Add(files);
}
if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
{
relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
}
foreach (var sourceFile in sourceFiles)
{
var destinationPath = sourceFile.ItemSpec;
var link = sourceFile.GetMetadata("Link");
if (!string.IsNullOrWhiteSpace(link))
{
destinationPath = link;
}
if (Path.IsPathRooted(destinationPath))
{
destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
}
if (!string.IsNullOrWhiteSpace(relativeTo))
{
if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
{
destinationPath = destinationPath.Substring(relativeTo.Length);
}
}
destinationPath = Path.Combine(targetDirectory, destinationPath);
var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);
sourceFilePath = Path.GetFullPath(sourceFilePath);
var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
if (isTypeScript)
{
if (IncludeTypeScriptSourceFiles)
{
files.Add(new XElement("file",
new XAttribute("src", sourceFilePath),
new XAttribute("target", destinationPath)
));
LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
}
var changedSource = Path.ChangeExtension(sourceFilePath, ".js");
var changedDestination = Path.ChangeExtension(destinationPath, ".js");
if (fileSystem.FileExists(changedSource))
{
files.Add(new XElement("file",
new XAttribute("src", changedSource),
new XAttribute("target", changedDestination)
));
LogMessage("Added file: " + changedDestination, MessageImportance.Normal);
}
}
else
{
files.Add(new XElement("file",
new XAttribute("src", sourceFilePath),
new XAttribute("target", destinationPath)
));
LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
}
}
}
示例7: UpdateVersionWithAppendValue
private void UpdateVersionWithAppendValue(XContainer nuSpec)
{
if (string.IsNullOrWhiteSpace(AppendToVersion))
{
return;
}
var package = nuSpec.ElementAnyNamespace("package");
if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
var metadata = package.ElementAnyNamespace("metadata");
if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
var version = metadata.ElementAnyNamespace("version");
if (version == null) throw new Exception(string.Format("The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid."));
version.Value = string.Format("{0}-{1}", PackageVersion ?? version.Value, AppendToVersion.Trim());
PackageVersion = version.Value;
}