private void EnsureNuGetBuild(bool fromActivation) { string solutionDirectory = _solutionManager.SolutionDirectory; string nugetFolderPath = Path.Combine(solutionDirectory, VsConstants.NuGetSolutionSettingsFolder); IFileSystem fileSystem = _fileSystemProvider.GetFileSystem(solutionDirectory); if (!fileSystem.DirectoryExists(VsConstants.NuGetSolutionSettingsFolder) || !fileSystem.FileExists(NuGetTargetsFile)) { // download NuGet.Build and NuGet.Bootstrapper packages into the .nuget folder IPackageRepository repository = _packageSourceProvider.GetAggregate(_packageRepositoryFactory, ignoreFailingRepositories: true); // Ensure we have packages before we attempt to add them. var installPackages = new [] { GetPackage(repository, NuGetBuildPackageName, fromActivation), GetPackage(repository, NuGetBootstrapperPackageName, fromActivation) }; foreach (var package in installPackages) { fileSystem.AddFiles(package.GetFiles(Constants.ToolsDirectory), VsConstants.NuGetSolutionSettingsFolder, preserveFilePath: false); } // IMPORTANT: do this BEFORE adding the .nuget folder to solution so that // the generated .nuget\nuget.config is included in the solution folder too. DisableSourceControlMode(); // now add the .nuget folder to the solution as a solution folder. _dte.Solution.AddFolderToSolution(VsConstants.NuGetSolutionSettingsFolder, nugetFolderPath); } }
private void EnsureNuGetBuild(bool fromActivation) { string solutionDirectory = _solutionManager.SolutionDirectory; string nugetFolderPath = Path.Combine(solutionDirectory, VsConstants.NuGetSolutionSettingsFolder); IFileSystem fileSystem = _fileSystemProvider.GetFileSystem(solutionDirectory); if (!fileSystem.DirectoryExists(VsConstants.NuGetSolutionSettingsFolder) || !fileSystem.FileExists(NuGetExeFile) || !fileSystem.FileExists(NuGetTargetsFile)) { // download NuGet.Build and NuGet.CommandLine packages into the .nuget folder, // using the active package source first and fall back to other enabled package sources. IPackageRepository repository = CreatePackageRestoreRepository(); var installPackages = new string[] { NuGetBuildPackageName, NuGetCommandLinePackageName }; foreach (var packageId in installPackages) { IPackage package = GetPackage(repository, packageId, fromActivation); if (package == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, VsResources.PackageRestoreDownloadPackageFailed, packageId)); } fileSystem.AddFiles(package.GetFiles(Constants.ToolsDirectory), VsConstants.NuGetSolutionSettingsFolder, preserveFilePath: false); } // IMPORTANT: do this BEFORE adding the .nuget folder to solution so that // the generated .nuget\nuget.config is included in the solution folder too. DisableSourceControlMode(); // now add the .nuget folder to the solution as a solution folder. _dte.Solution.AddFolderToSolution(VsConstants.NuGetSolutionSettingsFolder, nugetFolderPath); } }
public static void AddFiles(IFileSystem fileSystem, IEnumerable <IPackageFile> files, string rootDir) { fileSystem.AddFiles(files, rootDir, true); }