本文整理汇总了C#中Manifest.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Manifest.Save方法的具体用法?C# Manifest.Save怎么用?C# Manifest.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Manifest
的用法示例。
在下文中一共展示了Manifest.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSaveLoad
public void TestSaveLoad()
{
var manifest1 = new Manifest(ManifestFormat.Sha1New,
new ManifestDirectory("subdir"),
new ManifestNormalFile("abc123", new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), 3, "file"));
Manifest manifest2;
using (var tempFile = new TemporaryFile("0install-unit-tests"))
{
// Generate manifest, write it to a file and read the file again
manifest1.Save(tempFile);
manifest2 = Manifest.Load(tempFile, ManifestFormat.Sha1New);
}
// Ensure data stayed the same
manifest2.Should().Equal(manifest1);
}
示例2: ManifestSerialization
public void ManifestSerialization()
{
var manifest = new Manifest();
manifest.Metadata.Id = "id";
manifest.Metadata.Authors = "author";
manifest.Metadata.Version = "1.0.0";
manifest.Metadata.Description = "description";
manifest.Files = new List<ManifestFile>();
var file = new ManifestFile();
file.Source = "file_source";
file.Target = "file_target";
manifest.Files.Add(file);
var memoryStream = new MemoryStream();
manifest.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
// read the serialized manifest.
var newManifest = Manifest.ReadFrom(memoryStream, validateSchema: true);
Assert.Equal(newManifest.Metadata.Id, manifest.Metadata.Id);
Assert.Equal(newManifest.Metadata.Authors, manifest.Metadata.Authors);
Assert.Equal(newManifest.Metadata.Description, manifest.Metadata.Description);
Assert.Equal(newManifest.Files.Count, manifest.Files.Count);
for (int i = 0; i < newManifest.Files.Count; ++i)
{
Assert.Equal(newManifest.Files[i].Source, manifest.Files[i].Source);
Assert.Equal(newManifest.Files[i].Target, manifest.Files[i].Target);
}
}
示例3: ExecuteCommand
public override void ExecuteCommand()
{
var manifest = new Manifest();
string projectFile = null;
string fileName = null;
if (!String.IsNullOrEmpty(AssemblyPath))
{
// Extract metadata from the assembly
string path = Path.Combine(Directory.GetCurrentDirectory(), AssemblyPath);
AssemblyMetadata metadata = AssemblyMetadataExtractor.GetMetadata(path);
manifest.Metadata.Id = metadata.Name;
manifest.Metadata.Version = metadata.Version.ToString();
manifest.Metadata.Authors = metadata.Company;
manifest.Metadata.Description = metadata.Description;
}
else
{
if (!ProjectHelper.TryGetProjectFile(out projectFile))
{
manifest.Metadata.Id = Arguments.Any() ? Arguments[0] : "Package";
manifest.Metadata.Version = "1.0.0";
}
else
{
fileName = Path.GetFileNameWithoutExtension(projectFile);
manifest.Metadata.Id = "$id$";
manifest.Metadata.Title = "$title$";
manifest.Metadata.Version = "$version$";
manifest.Metadata.Description = "$description$";
manifest.Metadata.Authors = "$author$";
}
}
// Get the file name from the id or the project file
fileName = fileName ?? manifest.Metadata.Id;
// If we're using a project file then we want the a minimal nuspec
if (String.IsNullOrEmpty(projectFile))
{
manifest.Metadata.Description = manifest.Metadata.Description ?? SampleDescription;
if (String.IsNullOrEmpty(manifest.Metadata.Authors))
{
manifest.Metadata.Authors = Environment.UserName;
}
manifest.Metadata.DependencySets = new List<ManifestDependencySet>();
manifest.Metadata.DependencySets.Add(new ManifestDependencySet
{
Dependencies = new List<ManifestDependency> { SampleManifestDependency }
});
}
manifest.Metadata.ProjectUrl = SampleProjectUrl;
manifest.Metadata.LicenseUrl = SampleLicenseUrl;
manifest.Metadata.IconUrl = SampleIconUrl;
manifest.Metadata.Tags = SampleTags;
manifest.Metadata.Copyright = "Copyright " + DateTime.Now.Year;
manifest.Metadata.ReleaseNotes = SampleReleaseNotes;
string nuspecFile = fileName + Constants.ManifestExtension;
// Skip the creation if the file exists and force wasn't specified
if (File.Exists(nuspecFile) && !Force)
{
Console.WriteLine(NuGetResources.SpecCommandFileExists, nuspecFile);
}
else
{
try
{
using (var stream = new MemoryStream())
{
manifest.Save(stream, validate: false);
stream.Seek(0, SeekOrigin.Begin);
string content = stream.ReadToEnd();
File.WriteAllText(nuspecFile, RemoveSchemaNamespace(content));
}
Console.WriteLine(NuGetResources.SpecCommandCreatedNuSpec, nuspecFile);
}
catch
{
// Cleanup the file if it fails to save for some reason
File.Delete(nuspecFile);
throw;
}
}
}
示例4: CreateAndOutputNuSpecFile
private void CreateAndOutputNuSpecFile(string assemblyOutput, List<ManifestDependency> manifestDependencies)
{
var manifest = new Manifest
{
Metadata =
{
Dependencies = manifestDependencies,
Id = Id ?? assemblyOutput,
Title = Title ?? assemblyOutput,
Version = "$version$",
Description = Description ?? assemblyOutput,
Authors = Author ?? "$author$",
Tags = Tags ?? "$tags$",
LicenseUrl = LicenseUrl ?? "$licenseurl$",
RequireLicenseAcceptance = RequireLicenseAcceptance,
Copyright = Copyright ?? "$copyright$",
IconUrl = IconUrl ?? "$iconurl$",
ProjectUrl = ProjectUrl ?? "$projrcturl$",
Owners = Owners ?? Author ?? "$author$"
},
Files = new List<ManifestFile>
{
new ManifestFile
{
Source = assemblyOutput + ".dll",
Target = "lib"
}
}
};
string nuspecFile = assemblyOutput + Constants.ManifestExtension;
//Dont add a releasenotes node if we dont have any to add...
if (!string.IsNullOrEmpty(ReleaseNotes))
manifest.Metadata.ReleaseNotes = ReleaseNotes;
try
{
Console.WriteLine("Saving new NuSpec: {0}", nuspecFile);
using (var stream = new MemoryStream())
{
manifest.Save(stream, validate: false);
stream.Seek(0, SeekOrigin.Begin);
var content = stream.ReadToEnd();
File.WriteAllText(nuspecFile, RemoveSchemaNamespace(content));
}
}
catch (Exception)
{
Console.WriteError("Could not save file: {0}", nuspecFile);
throw;
}
}
示例5: ExecuteCommand
public override void ExecuteCommand()
{
var manifest = new Manifest();
string projectFile = null;
string fileName = null;
if (!String.IsNullOrEmpty(AssemblyPath)) {
// Extract metadata from the assembly
string path = Path.Combine(Directory.GetCurrentDirectory(), AssemblyPath);
AssemblyMetadata metadata = AssemblyMetadataExtractor.GetMetadata(path);
manifest.Metadata.Id = metadata.Name;
manifest.Metadata.Version = metadata.Version.ToString();
manifest.Metadata.Authors = metadata.Company;
manifest.Metadata.Description = metadata.Description;
}
else {
if (!CommandLineUtility.TryGetProjectFile(out projectFile)) {
manifest.Metadata.Id = Arguments.Any() ? Arguments[0] : "Package";
manifest.Metadata.Version = "1.0";
}
else {
fileName = Path.GetFileNameWithoutExtension(projectFile);
manifest.Metadata.Id = "$id$";
manifest.Metadata.Version = "$version$";
manifest.Metadata.Description = "$description$";
manifest.Metadata.Authors = "$author$";
}
}
// Get the file name from the id or the project file
fileName = fileName ?? manifest.Metadata.Id;
// If we're using a project file then we want the a minimal nuspec
if (String.IsNullOrEmpty(projectFile)) {
manifest.Metadata.Description = manifest.Metadata.Description ?? "Package description";
if (String.IsNullOrEmpty(manifest.Metadata.Authors)) {
manifest.Metadata.Authors = Environment.UserName;
}
manifest.Metadata.Dependencies = new List<ManifestDependency>();
manifest.Metadata.Dependencies.Add(new ManifestDependency { Id = "SampleDependency", Version = "1.0" });
}
manifest.Metadata.ProjectUrl = "http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE";
manifest.Metadata.LicenseUrl = "http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE";
manifest.Metadata.IconUrl = "http://ICON_URL_HERE_OR_DELETE_THIS_LINE";
manifest.Metadata.Tags = "Tag1 Tag2";
string nuspecFile = fileName + Constants.ManifestExtension;
// Skip the creation if the file exists and force wasn't specified
if (File.Exists(nuspecFile) && !Force) {
Console.WriteLine(NuGetResources.SpecCommandFileExists, nuspecFile);
}
else {
try {
using (Stream stream = File.Create(nuspecFile)) {
manifest.Save(stream, validate: false);
}
Console.WriteLine(NuGetResources.SpecCommandCreatedNuSpec, nuspecFile);
}
catch {
// Cleanup the file if it fails to save for some reason
File.Delete(nuspecFile);
throw;
}
}
}