本文整理汇总了C#中ProjectManager.RemovePackageReference方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectManager.RemovePackageReference方法的具体用法?C# ProjectManager.RemovePackageReference怎么用?C# ProjectManager.RemovePackageReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectManager
的用法示例。
在下文中一共展示了ProjectManager.RemovePackageReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: RemovingPackageDoesNotRemoveImportFileIfFilePatternDoesNotMatch
public void RemovingPackageDoesNotRemoveImportFileIfFilePatternDoesNotMatch()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"), "x:\\root");
projectSystem.AddImport(@"x:\root\A.1.0\content\net35\A.props", ProjectImportLocation.Top);
projectSystem.AddImport(@"x:\root\A.1.0\content\net35\A.targets", ProjectImportLocation.Bottom);
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
content: new[] { "net35\\A.1.0.props", "net35\\B.targets" });
projectManager.LocalRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.True(projectSystem.ImportExists(@"x:\root\A.1.0\content\net35\A.props"));
Assert.True(projectSystem.ImportExists(@"x:\root\A.1.0\content\net35\A.targets"));
}
示例3: RemovingPackageRemoveImportFile
public void RemovingPackageRemoveImportFile()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"), "x:\\root");
projectSystem.AddImport(@"x:\root\A.1.0\build\net35\A.props", ProjectImportLocation.Top);
projectSystem.AddImport(@"x:\root\A.1.0\build\net35\A.targets", ProjectImportLocation.Bottom);
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0");
var mockPackageA = Mock.Get(packageA);
var files = PackageUtility.CreateFiles(new[] { "build\\net35\\A.targets", "build\\net35\\a.props" });
mockPackageA.Setup(p => p.GetFiles()).Returns(files);
projectManager.LocalRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.False(projectSystem.ImportExists(@"x:\root\A.1.0\content\net35\A.props"));
Assert.False(projectSystem.ImportExists(@"x:\root\A.1.0\content\net35\A.targets"));
}
示例4: RemovePackageReferenceOnlyRemovedAssembliesFromTheTargetFramework
public void RemovePackageReferenceOnlyRemovedAssembliesFromTheTargetFramework()
{
// Arrange
var net20 = new FrameworkName(".NETFramework", new Version("2.0"));
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(net20);
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackageAssemblyReference net20Reference = PackageUtility.CreateAssemblyReference("foo.dll", net20);
IPackageAssemblyReference net40Reference = PackageUtility.CreateAssemblyReference("bar.dll", new FrameworkName(".NETFramework", new Version("4.0")));
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
content: null,
assemblyReferences: new[] { net20Reference, net40Reference },
tools: null,
dependencies: null,
downloadCount: 0,
description: null,
summary: null,
listed: true,
tags: null);
projectManager.LocalRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.Equal(1, projectSystem.Deleted.Count);
Assert.True(projectSystem.Deleted.Contains("foo.dll"));
}
示例5: RemovingPackageRemoveAssembliesCorrectlyAccordingToReferences3
public void RemovingPackageRemoveAssembliesCorrectlyAccordingToReferences3()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
projectSystem.AddReference("a.dll");
projectSystem.AddReference("b.dll");
projectSystem.AddReference("c.dll");
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
assemblyReferences: new[] { "lib\\net35\\a.dll", "lib\\net35\\b.dll" });
Mock<IPackage> mockPackageA = Mock.Get<IPackage>(packageA);
mockPackageA.Setup(m => m.PackageAssemblyReferences).Returns(
new PackageReferenceSet[] {
new PackageReferenceSet(VersionUtility.ParseFrameworkName("net50"), new [] { "a.dll" }),
new PackageReferenceSet(null, new [] { "b.dll" })
}
);
projectManager.LocalRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.True(projectSystem.ReferenceExists("a.dll"));
Assert.False(projectSystem.ReferenceExists("b.dll"));
Assert.True(projectSystem.ReferenceExists("c.dll"));
}
示例6: RemovingPackageReferenceRemovesPackageButNotDependencies
public void RemovingPackageReferenceRemovesPackageButNotDependencies()
{
// 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",
dependencies: new List<PackageDependency> {
new PackageDependency("B")
}, content: new[] { "A" });
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "B" });
projectManager.LocalRepository.AddPackage(packageA);
projectManager.LocalRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.True(projectManager.LocalRepository.Exists(packageB));
}
示例7: Uninstall
/// <summary>
/// Uninstalls a package.
/// </summary>
/// <param name="packageId">The package identifier for the package to be uninstalled.</param>
/// <param name="applicationPath">The application path.</param>
public void Uninstall(string packageId, string applicationPath) {
string solutionPath;
string extensionFullPath = string.Empty;
if (packageId.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme))) {
extensionFullPath = _virtualPathProvider.MapPath("~/Themes/" + packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme).Length));
} else if (packageId.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module))) {
extensionFullPath = _virtualPathProvider.MapPath("~/Modules/" + packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module).Length));
}
if (string.IsNullOrEmpty(extensionFullPath) ||
!Directory.Exists(extensionFullPath)) {
throw new OrchardException(T("Package not found: {0}", packageId));
}
// if we can access the parent directory, and the solution is inside, NuGet-uninstall the package here
if (TryGetSolutionPath(applicationPath, out solutionPath)) {
// this logger is used to render NuGet's log on the notifier
var logger = new NugetLogger(_notifier);
var installedPackagesPath = Path.Combine(solutionPath, PackagesPath);
var sourcePackageRepository = new LocalPackageRepository(installedPackagesPath);
try {
var project = new FileBasedProjectSystem(applicationPath) {Logger = logger};
var projectManager = new ProjectManager(
sourcePackageRepository,
new DefaultPackagePathResolver(installedPackagesPath),
project,
new ExtensionReferenceRepository(project, sourcePackageRepository, _extensionManager)
) {Logger = logger};
// add the package to the project
projectManager.RemovePackageReference(packageId);
}
catch {
// Uninstalling the package at the solution level failed
}
try {
var packageManager = new NuGetPackageManager(
sourcePackageRepository,
new DefaultPackagePathResolver(applicationPath),
new PhysicalFileSystem(installedPackagesPath) {Logger = logger}
) {Logger = logger};
packageManager.UninstallPackage(packageId);
}
catch {
// Package doesnt exist anymore
}
}
// If the package was not installed through nuget we still need to try to uninstall it by removing its directory
if (Directory.Exists(extensionFullPath)) {
Directory.Delete(extensionFullPath, true);
}
}
示例8: 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"));
}
示例9: RemovePackageWithTransformFileThatThrowsContinuesRemovingPackage
public void RemovePackageWithTransformFileThatThrowsContinuesRemovingPackage()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
var localRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config", () => { throw new UnauthorizedAccessException(); });
mockProjectSystem.AddFile("foo.txt");
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, localRepository);
var package = new Mock<IPackage>();
package.Setup(m => m.Id).Returns("A");
package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
var file = new Mock<IPackageFile>();
var contentFile = new Mock<IPackageFile>();
contentFile.Setup(m => m.Path).Returns(@"content\foo.txt");
contentFile.Setup(m => m.GetStream()).Returns(new MemoryStream());
contentFile.Setup(m => m.EffectivePath).Returns("foo.txt");
file.Setup(m => m.Path).Returns(@"content\web.config.transform");
file.Setup(m => m.EffectivePath).Returns("web.config.transform");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</system.web>
</configuration>
".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, contentFile.Object });
mockRepository.AddPackage(package.Object);
projectManager.LocalRepository.AddPackage(package.Object);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(mockProjectSystem.FileExists("foo.txt"));
Assert.False(localRepository.Exists(package.Object));
}
示例10: RemovePackageWithTransformFile
public void RemovePackageWithTransformFile()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config",
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" baz=""test"" />
</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"));
var file = new Mock<IPackageFile>();
file.Setup(m => m.Path).Returns(@"content\web.config.transform");
file.Setup(m => m.EffectivePath).Returns("web.config.transform");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</system.web>
</configuration>
".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
mockRepository.AddPackage(package.Object);
projectManager.LocalRepository.AddPackage(package.Object);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<system.web>
<compilation baz=""test"" />
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}
示例11: RemovePackageReferenceExcludesFileIfAnotherPackageUsesThem
public void RemovePackageReferenceExcludesFileIfAnotherPackageUsesThem()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "fileA", "commonFile" });
IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
new[] { "fileB", "commonFile" });
mockRepository.AddPackage(packageA);
mockRepository.AddPackage(packageB);
projectManager.AddPackageReference("A");
projectManager.AddPackageReference("B");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.True(mockProjectSystem.Deleted.Contains(@"fileA"));
Assert.True(mockProjectSystem.FileExists(@"commonFile"));
}
示例12: RemovePackageReferenceRaisesOnBeforeUninstallAndOnAfterUninstall
public void RemovePackageReferenceRaisesOnBeforeUninstallAndOnAfterUninstall()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { @"sub\file1", @"sub\file2" });
projectManager.PackageReferenceRemoving += (sender, e) =>
{
// Assert
Assert.Equal(e.InstallPath, @"x:\MockFileSystem\A.1.0");
Assert.Same(e.Package, packageA);
};
projectManager.PackageReferenceRemoved += (sender, e) =>
{
// Assert
Assert.Equal(e.InstallPath, @"x:\MockFileSystem\A.1.0");
Assert.Same(e.Package, packageA);
};
mockRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
// Act
projectManager.RemovePackageReference("A");
}
示例13: RemovingPackageReferenceWithNoDependents
public void RemovingPackageReferenceWithNoDependents()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var package = PackageUtility.CreatePackage("foo", "1.2.33", content: new[] { "file1" });
projectManager.LocalRepository.AddPackage(package);
sourceRepository.AddPackage(package);
// Act
projectManager.RemovePackageReference("foo");
// Assert
Assert.False(projectManager.LocalRepository.Exists(package));
}
示例14: RemovingPackageReferenceWithOtherProjectWithReferencesThatWereNotCopiedToProject
public void RemovingPackageReferenceWithOtherProjectWithReferencesThatWereNotCopiedToProject()
{
// 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 packageB = PackageUtility.CreatePackage("B", "1.0",
content: null,
assemblyReferences: new[] { PackageUtility.CreateAssemblyReference("foo.dll", new FrameworkName("SP", new Version("40.0"))) },
tools: null,
dependencies: null,
downloadCount: 0,
description: null,
summary: null,
listed: true,
tags: null);
projectManager.LocalRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA);
projectManager.LocalRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageB);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
}
示例15: RemovePackageReferenceRemoveContentAccordingToTargetFramework
public void RemovePackageReferenceRemoveContentAccordingToTargetFramework()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
projectSystem.AddFile("jQuery.js", "content\\[net35]\\jQuery.js");
projectSystem.AddFile("foo.css", "content\\foo.css");
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "net20\\contentFile", "net35\\jQuery.js", "foo.css" },
new[] { "lib\\eference.dll" });
mockRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
Assert.True(projectSystem.FileExists(@"contentFile"));
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.Equal(2, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"jQuery.js"));
Assert.True(projectSystem.FileExists(@"foo.css"));
Assert.False(localRepository.Exists("A"));
}