public async Task <InstalledPackagesResult> GetInstalledPackagesAsync(Guid projectId, CancellationToken cancellationToken) { // Just in case we're on the UI thread, switch to background thread. Very low cost (does not schedule new task) if already on background thread. await TaskScheduler.Default; NuGetProject project = await _solutionManager.GetNuGetProjectAsync(projectId.ToString()); if (project == null) { return(NuGetContractsFactory.CreateInstalledPackagesResult(InstalledPackageResultStatus.ProjectNotReady, packages: null)); } InstalledPackageResultStatus status; IReadOnlyCollection <NuGetInstalledPackage> installedPackages; switch (project) { case BuildIntegratedNuGetProject packageReferenceProject: (status, installedPackages) = await GetInstalledPackagesAsync(packageReferenceProject, cancellationToken); break; case MSBuildNuGetProject packagesConfigProject: (status, installedPackages) = await GetInstalledPackagesAsync(packagesConfigProject, cancellationToken); break; default: (status, installedPackages) = await GetInstalledPackagesAsync(project, cancellationToken); break; } return(NuGetContractsFactory.CreateInstalledPackagesResult(status, installedPackages)); }
/// <summary> /// Checks if the project is missing an assets file /// </summary> /// <param name="projectId"></param> /// <returns>True if it the assets file is missing</returns> public virtual async Task <bool> GetMissingAssetsFileStatusAsync(string projectId) { var nuGetProject = await _vsSolutionManager?.GetNuGetProjectAsync(projectId); if (nuGetProject?.ProjectStyle == ProjectModel.ProjectStyle.PackageReference && nuGetProject is BuildIntegratedNuGetProject buildIntegratedNuGetProject) { // When creating a new project, the assets file is not created until restore // and if there are no packages, we don't need the assets file in the PM UI var installedPackages = await buildIntegratedNuGetProject.GetInstalledPackagesAsync(CancellationToken.None); if (!installedPackages.Any()) { return(false); } string assetsFilePath = await buildIntegratedNuGetProject.GetAssetsFilePathAsync(); var fileInfo = new FileInfo(assetsFilePath); if (!fileInfo.Exists) { return(true); } } return(false); }
public async Task <InstalledPackagesResult> GetInstalledPackagesAsync(Guid projectId, CancellationToken cancellationToken) { const string etwEventName = nameof(INuGetProjectService) + "." + nameof(GetInstalledPackagesAsync); var eventData = new GetInstalledPackagesAsyncEventData() { Project = projectId }; using var _ = NuGetETW.ExtensibilityEventSource.StartStopEvent(etwEventName, eventData); try { // Just in case we're on the UI thread, switch to background thread. Very low cost (does not schedule new task) if already on background thread. await TaskScheduler.Default; NuGetProject project = await _solutionManager.GetNuGetProjectAsync(projectId.ToString()); if (project == null) { return(NuGetContractsFactory.CreateInstalledPackagesResult(InstalledPackageResultStatus.ProjectNotReady, packages: null)); } InstalledPackageResultStatus status; IReadOnlyCollection <NuGetInstalledPackage> installedPackages; switch (project) { case BuildIntegratedNuGetProject packageReferenceProject: (status, installedPackages) = await GetInstalledPackagesAsync(packageReferenceProject, cancellationToken); break; case MSBuildNuGetProject packagesConfigProject: (status, installedPackages) = await GetInstalledPackagesAsync(packagesConfigProject, cancellationToken); break; default: (status, installedPackages) = await GetInstalledPackagesAsync(project, cancellationToken); break; } return(NuGetContractsFactory.CreateInstalledPackagesResult(status, installedPackages)); } catch (Exception exception) { var extraProperties = new Dictionary <string, object>(); extraProperties["projectId"] = projectId.ToString(); await _telemetryProvider.PostFaultAsync(exception, typeof(NuGetProjectService).FullName, extraProperties : extraProperties); throw; } }
/// <summary> /// Checks if the project is missing an assets file /// </summary> /// <param name="projectId"></param> /// <returns>True if it the assets file is missing</returns> public virtual async Task <bool> GetMissingAssetsFileStatusAsync(string projectId) { var nuGetProject = await _vsSolutionManager?.GetNuGetProjectAsync(projectId); if (nuGetProject?.ProjectStyle == ProjectModel.ProjectStyle.PackageReference && nuGetProject is BuildIntegratedNuGetProject buildIntegratedNuGetProject) { string assetsFilePath = await buildIntegratedNuGetProject.GetAssetsFilePathAsync(); var fileInfo = new FileInfo(assetsFilePath); if (!fileInfo.Exists) { return(true); } } return(false); }