本文整理汇总了C#中ProjectManager.AddPackageReference方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectManager.AddPackageReference方法的具体用法?C# ProjectManager.AddPackageReference怎么用?C# ProjectManager.AddPackageReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectManager
的用法示例。
在下文中一共展示了ProjectManager.AddPackageReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPackageReferenceAppliesPackageReferencesCorrectly
public void AddPackageReferenceAppliesPackageReferencesCorrectly()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
assemblyReferences: new[] { "lib\\a.dll", "lib\\b.dll" });
sourceRepository.AddPackage(packageA);
Mock<IPackage> mockPackageA = Mock.Get<IPackage>(packageA);
mockPackageA.Setup(m => m.PackageAssemblyReferences).Returns(
new PackageReferenceSet[] {
new PackageReferenceSet(VersionUtility.ParseFrameworkName("net40"), new [] { "a.dll" }),
new PackageReferenceSet(null, new [] { "b.dll" })
}
);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.True(projectSystem.ReferenceExists("a.dll"));
Assert.False(projectSystem.ReferenceExists("b.dll"));
}
示例2: AddPackageReferenceLoadPackagesProjectNameConfigIfPresent
public void AddPackageReferenceLoadPackagesProjectNameConfigIfPresent()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(
new FrameworkName(".NETFramework, Version=4.5"));
projectSystem.ProjectName = "CoolProject";
projectSystem.AddFile("packages.CoolProject.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""luan"" version=""3.0"" />
</packages>");
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
assemblyReferences: new[] { "lib\\a.dll"});
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.True(projectManager.Project.FileExists("packages.CoolProject.config"));
Assert.False(projectManager.Project.FileExists("packages.config"));
}
示例3: AddPackage
public static void AddPackage(this DotNetProject project, IPackage package, IPackageRepository repository)
{
var packageManager = new PackageManager(repository, project.BaseDirectory);
packageManager.InstallPackage(package, false);
var projectSystem = new ProjectSystemWrapper(project);
var projectManager = new ProjectManager(repository, packageManager.PathResolver, projectSystem, packageManager.LocalRepository);
projectManager.AddPackageReference(package.Id);
project.NeedsReload = true;
}
示例4: AddPackageWithXdtTransformFile
public void AddPackageWithXdtTransformFile()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config",
@"<configuration>
<system.web>
<compilation debug=""true"" />
</system.web>
</configuration>
".AsStream());
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
var package = new Mock<IPackage>();
package.Setup(m => m.Id).Returns("A");
package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
package.Setup(m => m.Listed).Returns(true);
var file = new Mock<IPackageFile>();
file.Setup(m => m.Path).Returns(@"content\web.config.install.xdt");
file.Setup(m => m.EffectivePath).Returns("web.config.install.xdt");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
<system.web>
<compilation xdt:Locator=""Condition('@debug=true')"" debug=""false"" xdt:Transform=""Replace"" />
</system.web>
</configuration>".AsStream());
var file2 = new Mock<IPackageFile>();
file2.Setup(m => m.Path).Returns(@"content\web.config.uninstall.xdt");
file2.Setup(m => m.EffectivePath).Returns("web.config.uninstall.xdt");
file2.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
<system.web>
<compilation xdt:Locator=""Match(debug)"" debug=""false"" xdt:Transform=""Remove"" />
</system.web>
</configuration>".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, file2.Object });
mockRepository.AddPackage(package.Object);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(mockProjectSystem.FileExists("web.config.install.xdt"));
Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
Assert.True(mockProjectSystem.FileExists("web.config"));
Assert.Equal(
@"<configuration>
<system.web>
<compilation debug=""false""/>
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}
示例5: AddingPackageReferenceAddsPreprocessedFileToTargetPathWithRemovedExtension
public void AddingPackageReferenceAddsPreprocessedFileToTargetPathWithRemovedExtension()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { @"foo\bar\file.pp" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists(@"foo\bar\file.pp"));
Assert.True(projectSystem.FileExists(@"foo\bar\file"));
}
示例6: AddingPackageReferenceThrowsExceptionPackageReferenceIsAdded
public void AddingPackageReferenceThrowsExceptionPackageReferenceIsAdded()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new Mock<MockProjectSystem>() { CallBase = true };
projectSystem.Setup(m => m.AddFile("file", It.IsAny<Stream>())).Throws<UnauthorizedAccessException>();
projectSystem.Setup(m => m.Root).Returns("FakeRoot");
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "file" });
sourceRepository.AddPackage(packageA);
// Act
ExceptionAssert.Throws<UnauthorizedAccessException>(() => projectManager.AddPackageReference("A"));
// Assert
Assert.True(projectManager.LocalRepository.Exists(packageA));
}
示例7: Execute
//download the specified version of the package and update project reference to it. The newly downloaded package
//will be located in /packages folder. The updated project reference can be checked in corresponding .csproj file.
public bool Execute(string packageid, string projectFile, SemanticVersion version, string packages)
{
try
{
System.Console.WriteLine("-------------------------------------");
System.Console.WriteLine("Project File " + projectFile);
System.Console.WriteLine("Package "+packageid);
System.Console.WriteLine("Version "+version);
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
var packagePathResolver = new DefaultPackagePathResolver(packages);
var packagesFolderFileSystem = new PhysicalFileSystem(packages);
var projectSystem = new MSBuildProjectSystem(projectFile);
var localRepository = new LocalPackageRepository(packagePathResolver, packagesFolderFileSystem);
var projectManager = new ProjectManager(repo, packagePathResolver, projectSystem, localRepository);
projectManager.RemovePackageReference(packageid,true,false);
projectManager.AddPackageReference(packageid, version, true, false);
projectSystem.Save();
string filename = packageid + "." + version;
string[] s = Directory.GetFiles(packages+ @"\"+filename);
if (s.IsEmpty()) { System.Console.WriteLine("empty"); }
else
{
var nupkgFile = new PhysicalFileSystem(s[0]);
ZipPackage z = new ZipPackage(s[0]);
z.ExtractContents(nupkgFile, packages + @"\" + filename);
}
System.Console.WriteLine("Successfully updated");
return true;
}
catch (Exception e)
{
System.Console.Write("failure");
System.Console.Write(e.StackTrace);
return false;
}
}
示例8: AddPackageReferencePicksPortableLibraryAssemblyOverFallbackAssembly
public void AddPackageReferencePicksPortableLibraryAssemblyOverFallbackAssembly()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-sl4+net45"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "netcf\\you.dll", "lib\\portable-sl4+net45+wp8+windows8\\portable.dll", "lib\\me.dll" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.ReferenceExists("me.dll"));
Assert.False(projectSystem.ReferenceExists("you.dll"));
Assert.True(projectSystem.ReferenceExists("portable.dll"));
}
示例9: AddPackageReferencePickPortableDependencySetOverFallbackDependencySet
public void AddPackageReferencePickPortableDependencySetOverFallbackDependencySet()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-net45+wp8+windows8"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var dependencySets = new PackageDependencySet[]
{
new PackageDependencySet(targetFramework: null, dependencies: new [] { PackageDependency.CreateDependency("B", "1.0.0")}),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("net45"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("win8"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("wp8"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("portable-net45+win8+wp8"), dependencies: new PackageDependency[0] { }),
};
IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0", new[] { "me.txt" }, dependencySets: dependencySets);
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", new[] { "you.txt" });
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
// Act
projectManager.AddPackageReference("A", null, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(projectSystem.FileExists("me.txt"));
Assert.False(projectSystem.FileExists("you.txt"));
}
示例10: RemovingPackageWithModifiedContentFileWithinIgnoreMarkersSucceeds2
public void RemovingPackageWithModifiedContentFileWithinIgnoreMarkersSucceeds2()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(
sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.file" });
var contentFile = PackageUtility.CreateMockedPackageFile("content", "a.file", @"this is awesome.
*******NUGET: BEGIN LICENSE TEXT------------------
SDAFLKDSAJFL;KJDSAL;KFJL;DSAKJFL;KDSA
******NUGET: END LICENSE TEXT-------");
var mockPackageA = Mock.Get<IPackage>(packageA);
mockPackageA.Setup(p => p.GetFiles()).Returns(new[] { contentFile.Object });
sourceRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
Assert.True(projectManager.LocalRepository.Exists(packageA));
Assert.True(projectSystem.FileExists("a.file"));
projectSystem.ReadAllText("a.file");
// now modify 'a.file' to include ignore line markers
projectSystem.AddFile("a.file", @"this is awesome.");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.False(projectSystem.FileExists("a.file"));
}
示例11: AddPackageReferencePicksThePortableLibraryWithLeastPlatformsWhenInstalledIntoNonPortableProject
public void AddPackageReferencePicksThePortableLibraryWithLeastPlatformsWhenInstalledIntoNonPortableProject()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("netcore45"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
new[] { "portable-net45+sl4+win8+wp8\\zero.txt",
"portable-net45+win8+wp8\\one.txt",
"portable-net40+sl4+win8+wp71\\two.txt"});
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists("zero.txt"));
Assert.True(projectSystem.FileExists("one.txt"));
Assert.False(projectSystem.FileExists("two.txt"));
}
示例12: AddPackageReferencePicksThePortableLibraryWithHigherVersionOfTheMatchingFrameworks
public void AddPackageReferencePicksThePortableLibraryWithHigherVersionOfTheMatchingFrameworks(string contentFile, string otherContentFile)
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName("Silverlight, Version=4.0"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { contentFile, otherContentFile });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectSystem.FileExists("one.txt"));
Assert.False(projectSystem.FileExists("two.txt"));
}
示例13: AddPackageReferencePicksSpecificLibraryOverPortableOne
public void AddPackageReferencePicksSpecificLibraryOverPortableOne(string pickedContentFile, string projectFramework)
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(projectFramework));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "portable40-net40+wp7+silverlight4+windows\\two.txt", pickedContentFile});
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists("two.txt"));
Assert.True(projectSystem.FileExists("one.txt"));
}
示例14: RemovePackageReferenceRemoveDependencyPackageCorrectly2
public void RemovePackageReferenceRemoveDependencyPackageCorrectly2()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var dependencyB = new PackageDependency("B", null);
var dependencySetB = CreateDependencySet(".NETFramework, Version=2.1", dependencyB);
var dependencyC = new PackageDependency("C", null);
var dependencySetC = CreateDependencySet(".NETFramework, Version=2.0", dependencyC);
IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
dependencySets: new List<PackageDependencySet> { dependencySetB, dependencySetC },
content: new[] { "a.txt" });
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "b.txt" });
IPackage packageC = PackageUtility.CreatePackage("C", "2.0", content: new[] { "c.txt" });
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
projectManager.AddPackageReference("A");
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(projectManager.LocalRepository.Exists("C"));
Assert.True(projectSystem.FileExists("a.txt"));
Assert.False(projectSystem.FileExists("b.txt"));
Assert.True(projectSystem.FileExists("c.txt"));
// Act
projectManager.RemovePackageReference("A", forceRemove: false, removeDependencies: true);
Assert.False(projectManager.LocalRepository.Exists("A"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.False(projectManager.LocalRepository.Exists("C"));
Assert.False(projectSystem.FileExists("a.txt"));
Assert.False(projectSystem.FileExists("b.txt"));
Assert.False(projectSystem.FileExists("c.txt"));
}
示例15: AddPackageReferenceDoNotIncludeDependencyPackageIfTargetFrameworkDoesNotMatch
public void AddPackageReferenceDoNotIncludeDependencyPackageIfTargetFrameworkDoesNotMatch(string dependencyVersion)
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var dependency = new PackageDependency("B", null);
var dependencySet = new PackageDependencySet(
new FrameworkName(".NETFramework", new Version(dependencyVersion)),
new PackageDependency[] {dependency});
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.txt" });
Mock.Get(packageA).Setup(p => p.DependencySets).Returns(new [] {dependencySet});
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "b.txt" });
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(projectSystem.FileExists("a.txt"));
Assert.False(projectSystem.FileExists("b.txt"));
}