コード例 #1
0
        async void Install(object sender, EventArgs e)
        {
            var item = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null)
            {
                return;
            }

            var    dir = new DirectoryInfo(item.GetFullPath());
            string installDir;
            var    package = GetPackage(dir.Name, out installDir);

            if (package == null || package.Files == null || !package.Files.Any())
            {
                return;
            }

            string manifestPath = item.ContainingProject.GetConfigFile();

            var settings = new InstallSettings
            {
                InstallDirectory = Path.Combine(item.GetFullPath(), installDir),
                SaveManifest     = VSPackage.Options.SaveManifestFile
            };

            await PackageService.InstallpackageAsync(manifestPath, package, settings);

            var props = new Dictionary <string, string> {
                { "name", package.Name.ToLowerInvariant().Trim() },
                { "version", package.Version }
            };

            Telemetry.TrackEvent("Package installed", props);

            if (settings.SaveManifest)
            {
                item.ContainingProject.AddFileToProject(manifestPath, "None");
            }
        }