Пример #1
0
        public async Task <IEnumerable <MetadataReference> > AddPackage(string packageName, string packageVersion)
        {
            var package = await _lazyPackage.ValueAsync();

            var currentWorkspace = await package.CreateRoslynWorkspaceForRunAsync(new Budget());

            var currentRefs = new HashSet <string>(
                currentWorkspace.CurrentSolution.Projects.First().MetadataReferences
                .Select(m => m.Display));

            var dotnet = new Dotnet(package.Directory);
            var result = await dotnet.AddPackage(packageName, packageVersion);

            if (result.ExitCode != 0)
            {
                return(Array.Empty <MetadataReference>());
            }

            var newWorkspace = await package.CreateRoslynWorkspaceForRunAsync(new Budget());

            var newRefs = new HashSet <MetadataReference>(newWorkspace.CurrentSolution.Projects.First().MetadataReferences);

            var resultRefs = newRefs.Where(n => !currentRefs.Contains(n.Display));

            return(resultRefs);
        }
Пример #2
0
        public void AddPackageReference(string packageId, string version = null)
        {
            _addPackages.Add(packageId);
            _afterCreateActions.Add(async(package, budget) =>
            {
                Func <Task> action = async() =>
                {
                    var dotnet = new Dotnet(package.Directory);
                    await dotnet.AddPackage(packageId, version);
                };

                await action();
            });
        }