本文整理汇总了C#中PackageBuilder.Save方法的典型用法代码示例。如果您正苦于以下问题:C# PackageBuilder.Save方法的具体用法?C# PackageBuilder.Save怎么用?C# PackageBuilder.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackageBuilder
的用法示例。
在下文中一共展示了PackageBuilder.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServerPackageRepositoryReadsDerivedData
public void ServerPackageRepositoryReadsDerivedData()
{
// Arrange
var mockProjectSystem = new Mock<MockProjectSystem>() { CallBase = true };
var package = new PackageBuilder() { Id = "Test", Version = new System.Version("1.0"), Description = "Description" };
var mockFile = new Mock<IPackageFile>();
mockFile.Setup(m => m.Path).Returns("foo");
mockFile.Setup(m => m.GetStream()).Returns(new MemoryStream());
package.Files.Add(mockFile.Object);
package.Authors.Add("Test Author");
var memoryStream = new MemoryStream();
package.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
mockProjectSystem.Object.AddFile("foo.nupkg");
mockProjectSystem.Setup(c => c.OpenFile(It.IsAny<string>())).Returns(() => new MemoryStream(memoryStream.ToArray()));
var serverRepository = new ServerPackageRepository(new DefaultPackagePathResolver(mockProjectSystem.Object), mockProjectSystem.Object);
serverRepository.HashProvider = GetHashProvider();
// Act
var packages = serverRepository.GetPackagesWithDerivedData();
// Assert
byte[] data = memoryStream.ToArray();
Assert.AreEqual(data.Length, packages.Single().PackageSize);
CollectionAssert.AreEquivalent(data.Select(Invert).ToArray(), Convert.FromBase64String(packages.Single().PackageHash));
Assert.AreEqual(data.Length, packages.Single().PackageSize);
}
示例2: CreateTestPackage
/// <summary>
/// Creates a test package.
/// </summary>
/// <param name="packageId">The id of the created package.</param>
/// <param name="version">The version of the created package.</param>
/// <param name="path">The directory where the package is created.</param>
/// <returns>The full path of the created package file.</returns>
public static string CreateTestPackage(string packageId, string version, string path, Uri licenseUrl = null)
{
var packageBuilder = new PackageBuilder
{
Id = packageId,
Version = new SemanticVersion(version),
Description = "Test desc"
};
if (licenseUrl != null)
{
packageBuilder.LicenseUrl = licenseUrl;
}
var dependencies = new PackageDependency("Dummy");
packageBuilder.DependencySets.Add(new PackageDependencySet(null, new[] { dependencies }));
packageBuilder.Authors.Add("test author");
var packageFileName = string.Format("{0}.{1}.nupkg", packageId, version);
var packageFileFullPath = Path.Combine(path, packageFileName);
using (var fileStream = File.Create(packageFileFullPath))
{
packageBuilder.Save(fileStream);
}
return packageFileFullPath;
}
示例3: CtorWithStream
public void CtorWithStream()
{
// Arrange
var builder = new PackageBuilder();
builder.Id = "Package";
builder.Version = new SemanticVersion("1.0");
builder.Authors.Add("David");
builder.Description = "This is a test package";
builder.ReleaseNotes = "This is a release note.";
builder.Copyright = "Copyright";
builder.Files.AddRange(PackageUtility.CreateFiles(new[] { @"lib\40\A.dll", @"content\foo" }));
var ms = new MemoryStream();
builder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
// Act
var package = new ZipPackage(ms);
// Assert
Assert.Equal("Package", package.Id);
Assert.Equal(new SemanticVersion("1.0"), package.Version);
Assert.Equal("David", package.Authors.First());
Assert.Equal("Copyright", package.Copyright);
var files = package.GetFiles().ToList();
Assert.Equal(2, files.Count);
Assert.Equal(@"content\foo", files[0].Path);
Assert.Equal(@"lib\40\A.dll", files[1].Path);
var assemblyReferences = package.AssemblyReferences.ToList();
Assert.Equal(1, assemblyReferences.Count);
Assert.Equal("A.dll", assemblyReferences[0].Name);
Assert.Equal(new FrameworkName(".NETFramework", new Version("4.0")), assemblyReferences[0].TargetFramework);
Assert.Equal("This is a release note.", package.ReleaseNotes);
}
示例4: CreateTestPackage
/// <summary>
/// Creates a test package.
/// </summary>
/// <param name="packageId">The id of the created package.</param>
/// <param name="version">The version of the created package.</param>
/// <param name="path">The directory where the package is created.</param>
/// <returns>The full path of the created package file.</returns>
public static string CreateTestPackage(string packageId, string version, string path, Uri licenseUrl = null)
{
var packageBuilder = new PackageBuilder
{
Id = packageId,
Version = new SemanticVersion(version),
Description = "Test desc"
};
if (licenseUrl != null)
{
packageBuilder.LicenseUrl = licenseUrl;
}
packageBuilder.Files.Add(CreatePackageFile(@"content\test1.txt"));
packageBuilder.Authors.Add("test author");
var packageFileName = string.Format("{0}.{1}.nupkg", packageId, version);
var packageFileFullPath = Path.Combine(path, packageFileName);
using (var fileStream = File.Create(packageFileFullPath))
{
packageBuilder.Save(fileStream);
}
return packageFileFullPath;
}
示例5: GenerateSingleCustomPackage
public string GenerateSingleCustomPackage(PackageDefinition definition,
string binFolderPath,
string outputFolderPath,
string releaseVersion,
IEnumerable<string> singleDLLPackages,
IEnumerable<string> customPackages,
string packageNamePrefix)
{
// if no dependencies exist, don't create package from definition
IEnumerable<ManifestDependency> dependencies = this.GenerateDependencies(definition.Dependencies,
binFolderPath,
releaseVersion,
singleDLLPackages,
customPackages,
packageNamePrefix);
if (!dependencies.Any())
{
return String.Empty;
}
// Create nupkg file
var packageId = packageNamePrefix + definition.Id + "." + releaseVersion;
var nugetFilePath = Path.Combine(outputFolderPath, packageId + ".nupkg");
var metadata = new ManifestMetadata
{
Id = packageNamePrefix + definition.Id,
Title = packageNamePrefix + definition.Id,
Version = releaseVersion,
Tags = definition.Tag,
Authors = "Sitecore",
Owners = "Sitecore",
Description = definition.Description,
RequireLicenseAcceptance = false,
IconUrl = "http://www.sitecore.net/favicon.ico",
DependencySets = new List<ManifestDependencySet>
{
new ManifestDependencySet
{
Dependencies = dependencies.ToList()
}
}
};
var builder = new PackageBuilder();
builder.Populate(metadata);
using (FileStream stream = File.Open(nugetFilePath, FileMode.OpenOrCreate))
{
builder.Save(stream);
}
return nugetFilePath;
}
示例6: CreatePackage
public static string CreatePackage(string id, string version, string outputDirectory)
{
PackageBuilder builder = new PackageBuilder()
{
Id = id,
Version = new SemanticVersion(version),
Description = "Descriptions",
};
builder.Authors.Add("test");
builder.Files.Add(CreatePackageFile(@"content\test1.txt"));
var packageFileName = Path.Combine(outputDirectory, id + "." + version + ".nupkg");
using (var stream = new FileStream(packageFileName, FileMode.CreateNew))
{
builder.Save(stream);
}
return packageFileName;
}
示例7: BuildPackage
public void BuildPackage(string basePath, IList<string> includes, ManifestMetadata metadata, string outFolder, bool overwrite)
{
var nugetPkgBuilder = new PackageBuilder();
nugetPkgBuilder.PopulateFiles(basePath, includes.Select(i => new ManifestFile { Source = i }));
nugetPkgBuilder.Populate(metadata);
var filename = metadata.Id + "." + metadata.Version + ".nupkg";
var output = Path.Combine(outFolder, filename);
if (fileSystem.FileExists(output) && !overwrite)
throw new CommandException("The package file already exists and --overwrite was not specified");
log.Information("Saving {Filename} to {OutFolder}...", filename, outFolder);
fileSystem.EnsureDirectoryExists(outFolder);
using (var outStream = fileSystem.OpenFile(output, FileMode.Create))
nugetPkgBuilder.Save(outStream);
}
示例8: CtorWithStream
public void CtorWithStream()
{
// Arrange
var builder = new PackageBuilder();
builder.Id = "Package";
builder.Version = new SemanticVersion("1.0");
builder.Authors.Add("David");
builder.Description = "This is a test package";
builder.ReleaseNotes = "This is a release note.";
builder.Copyright = "Copyright";
builder.Files.AddRange(PackageUtility.CreateFiles(new[] { PathFixUtility.FixPath(@"lib\40\A.dll"), PathFixUtility.FixPath(@"content\foo") }));
var ms = new MemoryStream();
builder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
// Act
var package = new ZipPackage(ms);
// Assert
Assert.Equal("Package", package.Id);
Assert.Equal(new SemanticVersion("1.0"), package.Version);
Assert.Equal("David", package.Authors.First());
Assert.Equal("Copyright", package.Copyright);
//Order is not gauranteed (or required) from GetFiles(),
//but we rely on the order for a few of the asserts,
//and it appears to not behave the same way on Mono,
//so we call "order by" here to force a specific order.
var files = package.GetFiles().OrderBy(k => k.Path).ToList();
Assert.Equal(2, files.Count);
Assert.Equal(PathFixUtility.FixPath(@"content\foo"), files[0].Path);
Assert.Equal(PathFixUtility.FixPath(@"lib\40\A.dll"), files[1].Path);
var assemblyReferences = package.AssemblyReferences.ToList();
Assert.Equal(1, assemblyReferences.Count);
Assert.Equal("A.dll", assemblyReferences[0].Name);
Assert.Equal(new FrameworkName(".NETFramework", new Version("4.0")), assemblyReferences[0].TargetFramework);
Assert.Equal("This is a release note.", package.ReleaseNotes);
}
示例9: PackageBuilderWorksWithFileNamesContainingSpecialCharacters
public void PackageBuilderWorksWithFileNamesContainingSpecialCharacters()
{
// Arrange
var fileNames = new[] {
@"lib\regular.file.dll",
@"lib\name with spaces.dll",
@"lib\C#\test.dll",
@"content\images\logo123?#78.png",
@"content\images\bread&butter.jpg",
};
// Act
var builder = new PackageBuilder { Id = "test", Version = new SemanticVersion("1.0"), Description = "test" };
builder.Authors.Add("test");
foreach (var name in fileNames)
{
builder.Files.Add(CreatePackageFile(name));
}
// Assert
using (MemoryStream stream = new MemoryStream())
{
builder.Save(stream);
var zipPackage = new ZipPackage(() => new MemoryStream(stream.ToArray()), enableCaching: false);
Assert.Equal(@"content\images\bread&butter.jpg", zipPackage.GetFiles().ElementAt(0).Path);
Assert.Equal(@"content\images\logo123?#78.png", zipPackage.GetFiles().ElementAt(1).Path);
Assert.Equal(@"lib\C#\test.dll", zipPackage.GetFiles().ElementAt(2).Path);
Assert.Equal(@"lib\name with spaces.dll", zipPackage.GetFiles().ElementAt(3).Path);
Assert.Equal(@"lib\regular.file.dll", zipPackage.GetFiles().ElementAt(4).Path);
}
}
示例10: PackageBuilderThrowsIfSpecialVersionExceedsMaxLengthLimit
public void PackageBuilderThrowsIfSpecialVersionExceedsMaxLengthLimit()
{
// Arrange
var builder = new PackageBuilder
{
Id = "cool",
Version = new SemanticVersion("1.0-vvvvvvvvvvvvvvvvvvvvK"),
Description = "Description"
};
builder.Authors.Add("Me");
var dependencies = new PackageDependency[] {
new PackageDependency("X")
};
builder.DependencySets.Add(new PackageDependencySet(null, dependencies));
// Act & Assert
ExceptionAssert.Throws<InvalidOperationException>(() => builder.Save(new MemoryStream()), "The special version part cannot exceed 20 characters.");
}
示例11: CreatePackageUsesV5SchemaNamespaceIfDevelopmentDependency
public void CreatePackageUsesV5SchemaNamespaceIfDevelopmentDependency()
{
// Arrange
PackageBuilder builder = new PackageBuilder()
{
Id = "A",
Version = new SemanticVersion("1.0"),
Description = "Descriptions",
DevelopmentDependency = true
};
builder.Authors.Add("JaneDoe");
builder.PackageAssemblyReferences.Add(
new PackageReferenceSet(
new FrameworkName(".NET, Version=3.0"),
new[] { "one.dll" }));
builder.Files.Add(CreatePackageFile("lib\\one.dll"));
using (var ms = new MemoryStream())
{
builder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
var manifestStream = GetManifestStream(ms);
// Assert
Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd"">
<metadata>
<id>A</id>
<version>1.0</version>
<authors>JaneDoe</authors>
<owners>JaneDoe</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<developmentDependency>true</developmentDependency>
<description>Descriptions</description>
<references>
<group targetFramework="".NET3.0"">
<reference file=""one.dll"" />
</group>
</references>
</metadata>
</package>", manifestStream.ReadToEnd());
}
}
示例12: SaveThrowsIfNoFilesOrDependencies
public void SaveThrowsIfNoFilesOrDependencies()
{
// Arrange
var builder = new PackageBuilder();
builder.Id = "A";
builder.Version = new SemanticVersion("1.0");
builder.Description = "Description";
// Act & Assert
ExceptionAssert.Throws<InvalidOperationException>(() => builder.Save(new MemoryStream()), "Cannot create a package that has no dependencies nor content.");
}
示例13: SavingPackageValidatesReferences
public void SavingPackageValidatesReferences()
{
// Arrange
var builder = new PackageBuilder
{
Id = "A",
Version = new SemanticVersion("1.0"),
Description = "Test",
};
builder.Authors.Add("Test");
builder.Files.Add(new PhysicalPackageFile { TargetPath = @"lib\Foo.dll" });
builder.PackageAssemblyReferences.Add(new PackageReferenceSet(null, new string[] { "Bar.dll" }));
ExceptionAssert.Throws<InvalidDataException>(() => builder.Save(new MemoryStream()),
"Invalid assembly reference 'Bar.dll'. Ensure that a file named 'Bar.dll' exists in the lib directory.");
}
示例14: CreatePackageDoesNotUseV5SchemaNamespaceIfReferencesHasOnlyNullTargetFramework
public void CreatePackageDoesNotUseV5SchemaNamespaceIfReferencesHasOnlyNullTargetFramework()
{
// Arrange
PackageBuilder builder = new PackageBuilder()
{
Id = "A",
Version = new SemanticVersion("1.0"),
Description = "Descriptions",
};
builder.Authors.Add("Luan");
builder.PackageAssemblyReferences.Add(
new PackageReferenceSet(
null,
new[] { "one.dll" }));
builder.Files.Add(CreatePackageFile("lib\\one.dll"));
using (var ms = new MemoryStream())
{
builder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
var manifestStream = GetManifestStream(ms);
// Assert
Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
<metadata>
<id>A</id>
<version>1.0</version>
<authors>Luan</authors>
<owners>Luan</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Descriptions</description>
<references>
<reference file=""one.dll"" />
</references>
</metadata>
</package>", manifestStream.ReadToEnd());
}
}
示例15: BuildPackage
private void BuildPackage(PackageBuilder builder, bool analyzePackage, string outputPath = null)
{
if (!String.IsNullOrEmpty(Version))
{
builder.Version = new SemanticVersion(Version);
}
if (_minClientVersionValue != null)
{
builder.MinClientVersion = _minClientVersionValue;
}
outputPath = outputPath ?? GetOutputPath(builder);
ExcludeFiles(builder.Files);
// Track if the package file was already present on disk
bool isExistingPackage = File.Exists(outputPath);
try
{
using (Stream stream = File.Create(outputPath))
{
builder.Save(stream);
}
}
catch
{
if (!isExistingPackage && File.Exists(outputPath))
{
File.Delete(outputPath);
}
throw;
}
if (Verbosity == Verbosity.Detailed)
{
PrintVerbose(outputPath);
}
var package = new OptimizedZipPackage(outputPath);
if (analyzePackage)
{
AnalyzePackage(package);
}
Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandSuccess"), outputPath);
}