Example #1
0
        public void AddEntryIndented()
        {
            var data   = @"
    ### Generated by the tool
    ### End of generated by the tool
";
            var writer = new WorkspaceWriter();
            var entry  = new WorkspaceEntry()
            {
                PackageIdentity = new PackageIdentity("remotion.linq", new NuGetVersion(2, 2, 0))
            };

            var result = writer.AddEntry(data, entry, true);

            result = result.Replace("\r", "");

            var tocompare = @"
    ### Generated by the tool
    nuget_package(
        name = ""remotion.linq"",
        package = ""remotion.linq"",
        version = ""2.2.0"",
    )
    ### End of generated by the tool
".Replace("\r", "");

            Assert.Equal(tocompare, result);
        }
Example #2
0
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageIdentity.Id, new VersionRange(packageIdentity.Version));

            var json = await GetJsonAsync();

            JsonConfigUtility.AddDependency(json, dependency);
            await SaveJsonAsync(json);

            var packageReader = downloadResourceResult.PackageReader
                                ?? new PackageArchiveReader(downloadResourceResult.PackageStream, leaveStreamOpen: true);
            IAsyncPackageContentReader packageContentReader = packageReader;
            IAsyncPackageCoreReader    packageCoreReader    = packageReader;

            var libItemGroups = await packageContentReader.GetLibItemsAsync(token);

            var referenceItemGroups = await packageContentReader.GetReferenceItemsAsync(token);

            var frameworkReferenceGroups = await packageContentReader.GetFrameworkItemsAsync(token);

            var contentFileGroups = await packageContentReader.GetContentItemsAsync(token);

            var buildFileGroups = await packageContentReader.GetBuildItemsAsync(token);

            var toolItemGroups = await packageContentReader.GetToolItemsAsync(token);

            var depsGroups = await packageContentReader.GetPackageDependenciesAsync(token);

            IEnumerable <FrameworkSpecificGroup> refItemGroups = null;

            if (packageReader is PackageArchiveReader reader)
            {
                refItemGroups = await reader.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }
            else if (packageReader is PackageFolderReader reader2)
            {
                refItemGroups = await reader2.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }

            var deps  = (PackageDependencyInfo)NuGetProjectActions.First(x => x.PackageIdentity.Equals(packageIdentity)).PackageIdentity;
            var entry = new WorkspaceEntry(packageIdentity, GetSha(downloadResourceResult.PackageStream),
                                           depsGroups, libItemGroups, toolItemGroups, refItemGroups, _mainFile);

            if (!SdkList.Dlls.Contains(entry.PackageIdentity.Id.ToLower()))
            {
                var workspace = await GetWorkspaceAsync();

                var updater = new WorkspaceWriter();
                var updated = updater.AddEntry(workspace, entry);
                await SaveWorkspaceAsync(updated);
            }

            return(await base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
        }
        public virtual async Task AddEntry(WorkspaceEntry entry)
        {
            var workspace = await GetWorkspaceAsync();

            var updater = new WorkspaceWriter();
            var updated = updater.AddEntry(workspace, entry, ProjectConfig.Indent);

            await SaveWorkspaceAsync(updated);
        }
Example #4
0
        public override async Task <bool> UninstallPackageAsync(
            PackageIdentity packageIdentity,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var json = await GetJsonAsync();

            JsonConfigUtility.RemoveDependency(json, packageIdentity.Id);
            await SaveJsonAsync(json);

            var workspace = await GetWorkspaceAsync();

            var updater = new WorkspaceWriter();
            var updated = updater.RemoveEntry(workspace, packageIdentity.Id);

            await SaveWorkspaceAsync(updated);

            return(await base.UninstallPackageAsync(packageIdentity, nuGetProjectContext, token));
        }
Example #5
0
        public void SingleEntry()
        {
            var data    = @"
### Generated by the tool
nuget_package(
   name = ""remotion.linq"",
   package = ""remotion.linq"",
   version = ""2.2.0"",
)
### End of generated by the tool
";
            var writer  = new WorkspaceWriter();
            var section = writer.ExtractSection(data);

            var parser = new WorkspaceParser(section);
            var result = parser.Parse();

            Assert.Single(result);
            var entry = result.First();

            Assert.Equal("remotion.linq", entry.PackageIdentity.Id);
            Assert.Equal("2.2.0", entry.PackageIdentity.Version.ToString());
        }