Пример #1
0
        public async Task <ActionResult> VsixContent(string id, string version)
        {
            string fileName = string.Format(Constants.PackageFileSavePathTemplate, id.ToLower(), version.ToLower(), Constants.NuGetPackageFileExtension);
            var    file     = await _fileStorageService.GetFileReferenceAsync(Constants.PackagesFolderName, fileName);

            if (file == null)
            {
                return(HttpNotFound());
            }

            using (var stream = file.OpenRead())
            {
                using (var pkg = new Nupkg(stream, true))
                {
                    string embeddedFileName = pkg.GetFiles().FirstOrDefault(f => Path.GetExtension(f).Equals(".vsix", StringComparison.OrdinalIgnoreCase));

                    var vsix = pkg.GetFileStream(embeddedFileName);
                    if (vsix != null)
                    {
                        return(new FileStreamResult(vsix, "application/octet-stream")
                        {
                            FileDownloadName = Path.GetFileName(embeddedFileName)
                        });
                    }
                }
            }

            return(HttpNotFound());
        }
Пример #2
0
        public void can_include_files_from_nuspec_with_target()
        {
            var output = moo("pack my_nuspecs/file-src-with-target.nuspec");

            var nupkg = new Nupkg(PathToTemp("working", "my_nuspecs", "file-src-with-target-1.0.nupkg"));

            nupkg.Exists().Should(Be.True);
            nupkg.Files.ShouldEqual(new List <string> {
                "file-src-with-target.nuspec",
                "foo/README"
            });
        }
Пример #3
0
        public void can_include_files_from_nuspec_with_target_with_wildcards()
        {
            var output = moo("pack my_nuspecs/file-src-with-target-with-wildcard.nuspec");

            var nupkg = new Nupkg(PathToTemp("working", "my_nuspecs", "file-src-with-target-with-wildcard-1.0.nupkg"));

            nupkg.Exists().Should(Be.True);
            nupkg.Files.ShouldEqual(new List <string> {
                "file-src-with-target-with-wildcard.nuspec",
                "foo/Doc.txt",
                "foo/InSubdir"                 // <--- when you use Target, everything gets flattened
            });
        }
Пример #4
0
        public void can_include_files_from_nuspec_with_wildcards()
        {
            var output = moo("pack my_nuspecs/file-src-with-wildcard.nuspec");

            var nupkg = new Nupkg(PathToTemp("working", "my_nuspecs", "file-src-with-wildcard-1.0.nupkg"));

            nupkg.Exists().Should(Be.True);
            nupkg.Files.ShouldEqual(new List <string> {
                "file-src-with-wildcard.nuspec",
                "doc/Doc.txt",
                "doc/subdir/InSubdir"
            });
        }
Пример #5
0
        public void Unpack()
        {
            var tool = new Nupkg(PathToContent("package_working_directories/just-a-tool-1.0.0.0.nupkg"));

            // if extract to existing directory, extracts into it
            var dir = PathToTemp("ExtractHere").AsDir().Create();

            PathToTemp("ExtractHere").AsDir().Exists().Should(Be.True);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0").AsDir().Exists().Should(Be.False);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "tools").AsDir().Exists().Should(Be.False);

            var unpacked = tool.Unpack(dir.Path);

            unpacked.Should(Be.InstanceOf(typeof(UnpackedNupkg)));
            unpacked.Path.ShouldEqual(PathToTemp("ExtractHere", "just-a-tool-1.0.0.0"));
            unpacked.Id.ShouldEqual("just-a-tool");
            (unpacked as UnpackedNupkg).Nuspec.Path.ShouldEqual(PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "just-a-tool.nuspec"));
            unpacked.Tools.ShouldEqual(new List <string> {
                PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "tools", "tool.exe")
            });

            PathToTemp("ExtractHere").AsDir().Exists().Should(Be.True);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0").AsDir().Exists().Should(Be.True);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "tools").AsDir().Exists().Should(Be.True);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "just-a-tool.nuspec").AsFile().Exists().Should(Be.True);
            PathToTemp("ExtractHere", "just-a-tool-1.0.0.0", "tools", "tool.exe").AsFile().Exists().Should(Be.True);

            // if extract to new directory, extract exactly there
            PathToTemp("Exact_Dir").AsDir().Exists().Should(Be.False);
            PathToTemp("Exact_Dir", "tools").AsDir().Exists().Should(Be.False);

            unpacked = tool.Unpack(PathToTemp("Exact_Dir"));

            unpacked.Should(Be.InstanceOf(typeof(UnpackedNupkg)));
            unpacked.Path.ShouldEqual(PathToTemp("Exact_Dir"));
            unpacked.Id.ShouldEqual("just-a-tool");
            (unpacked as UnpackedNupkg).Nuspec.Path.ShouldEqual(PathToTemp("Exact_Dir", "just-a-tool.nuspec"));
            unpacked.Tools.ShouldEqual(new List <string> {
                PathToTemp("Exact_Dir", "tools", "tool.exe")
            });

            PathToTemp("Exact_Dir").AsDir().Exists().Should(Be.True);
            PathToTemp("Exact_Dir", "tools").AsDir().Exists().Should(Be.True);
            PathToTemp("Exact_Dir", "just-a-tool.nuspec").AsFile().Exists().Should(Be.True);
            PathToTemp("Exact_Dir", "tools", "tool.exe").AsFile().Exists().Should(Be.True);

            // it should name the directory using the package id and version, not the name of the .nupkg file ...
            PathToTemp("MarkdownSharp-1.13.0.0").AsDir().Exists().Should(Be.False);
            new Nupkg(PathToContent("packages/unnamed.nupkg")).Unpack(PathToTemp(""));
            PathToTemp("MarkdownSharp-1.13.0.0").AsDir().Exists().Should(Be.True);
        }
Пример #6
0
        public bool NupkgDetermineNugetInfoTest(string filename)
        {
            if (File.Exists(filename) == false)
            {
                File.WriteAllText(filename, "essentially fake nuget package");
            }
            var fi    = new FileInfo(filename);
            var nupkg = new Nupkg()
            {
                Path          = filename,
                PathSha1      = filename.ToSha1(),
                PackageSha256 = fi.ToSha256(),
            }.DetermineNugetInfo();

            return($"{nupkg.PackageName}.{nupkg.Version}.nupkg" == filename);
        }
        private async Task EnsureNuGetExe()
        {
            if (await _fileStorageService.FileExistsAsync(Constants.DownloadsFolderName, "nuget.exe"))
            {
                // Ensure the file exists on blob storage.
                return;
            }

            var package = _packageService.FindPackageByIdAndVersion("NuGet.CommandLine", version: null, allowPrerelease: false);
            if (package == null)
            {
                throw new InvalidOperationException("Unable to find NuGet.CommandLine.");
            }

            using (Stream packageStream = await _packageFileService.DownloadPackageFileAsync(package))
            {
                var nupkg = new Nupkg(packageStream, leaveOpen: true);
                await ExtractNuGetExe(nupkg);
            }
        }
Пример #8
0
        public ViewModelFiles(IPreferenceService preferenceService,
                              IFileService fileService,
                              IRunNuget runNuget)
        {
            PreferenceService  = preferenceService;
            FileService        = fileService;
            _runNuget          = runNuget;
            BsFiles.DataSource = new List <IFile>();
            PropertyChanged   += async(s, e) => {
                Console.WriteLine(e.PropertyName);
                switch (e.PropertyName)
                {
                case nameof(TextSearch):
                case nameof(CheckCsProj):
                case nameof(CheckVbProj):
                case nameof(CheckNupkg):
                case nameof(CheckSln):
                case nameof(CheckNuspec):
                case nameof(CheckSnupkg):
                    await UpdateFilesData();

                    break;

                case nameof(OptionPack):
                case nameof(OptionRestore):
                case nameof(OptionList):
                    break;

                case nameof(OptionDelete):
                case nameof(OptionAddNupkg):
                    CheckProductionSource = true;
                    break;
                }
            };
            _runNuget.GetCmdStandardOutput += async(s, e) => {
                try {
                    if (e.Contains("Successfully created package"))
                    {
                        var pathLine = e.Split("'".ToArray(), StringSplitOptions.RemoveEmptyEntries).LastOrDefault(x => x.Contains(":\\") && x.Contains(".nupkg"));
                        if (pathLine != null && File.Exists(pathLine))
                        {
                            var createFileInfo = new FileInfo(pathLine);
                            if (CheckDevSource)
                            {
                                var devSourceCopy = await PreferenceService.GetSetting(Settings.NugetLocalDevNugetServer);

                                if (!string.IsNullOrWhiteSpace(devSourceCopy.ValueString))
                                {
                                    var devSourceFileInfo = new FileInfo(Path.Combine(devSourceCopy.ValueString, createFileInfo.Name));
                                    File.Copy(createFileInfo.FullName, devSourceFileInfo.FullName, true);
                                }
                            }
                            try {
                                var newNupkg = new Nupkg()
                                {
                                    Path          = pathLine,
                                    PathSha1      = pathLine.ToSha1(),
                                    ProjectID     = (SelectedFile as Project)?.ID ?? 0,
                                    PackageSha256 = createFileInfo.ToSha256(),
                                }.DetermineNugetInfo();
                                await FileService.WriteFileToStorage(newNupkg);
                            } catch (Exception ex) {
                                MessageBox.Show($"Writing new nuget package to storage failed:\r\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show($"ViewModelFiles:\r\n{ex.Message}", "Error: copying to Dev Source", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };
        }