/// <summary> /// Checks if there are missing packages that should be restored. If so, a warning will /// be added to the error list. /// </summary> private void CheckForMissingPackages() { var missingPackages = new List <PackageReference>(); var repoSettings = ServiceLocator.GetInstance <IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); missingPackages.AddRange(GetMissingPackages(_packageReferenceFileList.SolutionPackageReferenceFile, fileSystem)); foreach (var projectReferenceFile in _packageReferenceFileList.ProjectPackageReferenceFiles) { if (HasCanceled()) { return; } missingPackages.AddRange(GetMissingPackages(projectReferenceFile.FullPath, fileSystem)); } if (missingPackages.Count > 0) { var errorText = String.Format(CultureInfo.CurrentCulture, Resources.PackageNotRestoredBecauseOfNoConsent, String.Join(", ", missingPackages.Select(p => p.ToString()))); VsUtility.ShowError(_errorListProvider, TaskErrorCategory.Error, TaskPriority.High, errorText, hierarchyItem: null); } }
/// <summary> /// Gets package reference file(s) used by the project, or subprojects if the project is a solution folder, /// and adds the files into list _projectPackageReferenceFiles. /// </summary> /// <param name="project">the project to inspect.</param> private void GetPackageReferenceFiles(Project project) { if (project == null) { return; } // Ignore "Miscellaneous Files" project if (VsConstants.VsProjectKindMisc.Equals(project.Kind, StringComparison.OrdinalIgnoreCase)) { return; } if (VsConstants.VsProjectItemKindSolutionFolder.Equals(project.Kind, StringComparison.OrdinalIgnoreCase)) { foreach (ProjectItem item in project.ProjectItems) { var nestedProject = item.SubProject; GetPackageReferenceFiles(nestedProject); } } else { Tuple <string, string> packageReferenceFiles = VsUtility.GetPackageReferenceFileFullPaths(project); if (File.Exists(packageReferenceFiles.Item1)) { _projectPackageReferenceFiles.Add(new ProjectPackageReferenceFile(project, packageReferenceFiles.Item1)); } else if (File.Exists(packageReferenceFiles.Item2)) { _projectPackageReferenceFiles.Add(new ProjectPackageReferenceFile(project, packageReferenceFiles.Item2)); } } }
private void ShowRetargetingErrorTask(IEnumerable <string> packagesToBeReinstalled, IVsHierarchy projectHierarchy, TaskErrorCategory errorCategory, TaskPriority priority) { Debug.Assert(packagesToBeReinstalled != null && !packagesToBeReinstalled.IsEmpty()); var errorText = String.Format(CultureInfo.CurrentCulture, Resources.ProjectUpgradeAndRetargetErrorMessage, String.Join(", ", packagesToBeReinstalled)); VsUtility.ShowError(_errorListProvider, errorCategory, priority, errorText, projectHierarchy); }
/// <summary> /// Gets the list of packages to be reinstalled based on the Project instance and the localRepository to find packages in /// </summary> /// <param name="project">Project for which packages to be reinstalled are determined</param> /// <param name="localRepository">Local Repository from which packages listed in project's packages.config are loaded</param> /// <returns></returns> internal static IList <IPackage> GetPackagesToBeReinstalled(Project project, IPackageRepository localRepository) { Debug.Assert(project != null); // First call to VsUtility.PackageConfigExists(project) checks if there is a packages.config file under the project folder, Otherwise, return emtpy list // If present, then call VsUtility.IsNuGetInUse to see if NuGet is used in the project. The second call might result in loading of NuGet.VisualStudio.dll if (localRepository != null && VsUtility.PackagesConfigExists(project) && project.IsNuGetInUse()) { return(GetPackagesToBeReinstalled(project.GetTargetFrameworkName(), GetPackageReferences(project), localRepository)); } return(new List <IPackage>()); }
private PackageManagerControl GetProjectPackageManagerControl(string projectUniqueName) { return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var uiShell = ServiceLocator.GetGlobalService <SVsUIShell, IVsUIShell>(); foreach (var windowFrame in VsUtility.GetDocumentWindows(uiShell)) { object docView; var hr = windowFrame.GetProperty( (int)__VSFPROPID.VSFPROPID_DocView, out docView); if (hr == VSConstants.S_OK && docView is PackageManagerWindowPane) { var packageManagerWindowPane = (PackageManagerWindowPane)docView; if (packageManagerWindowPane.Model.IsSolution) { // the window is the solution package manager continue; } var projects = packageManagerWindowPane.Model.Context.Projects; if (projects.Count() != 1) { continue; } IProjectContextInfo existingProject = projects.First(); IServiceBroker serviceBroker = packageManagerWindowPane.Model.Context.ServiceBroker; IProjectMetadataContextInfo projectMetadata = await existingProject.GetMetadataAsync( serviceBroker, CancellationToken.None); if (string.Equals(projectMetadata.Name, projectUniqueName, StringComparison.OrdinalIgnoreCase)) { var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame); if (packageManagerControl != null) { return packageManagerControl; } } } } return null; })); }
private static PackageReferenceFile GetPackageReferenceFile(Project project) { Debug.Assert(project != null); Tuple <string, string> packageReferenceFiles = VsUtility.GetPackageReferenceFileFullPaths(project); if (File.Exists(packageReferenceFiles.Item1)) { return(new PackageReferenceFile(packageReferenceFiles.Item1)); } else if (File.Exists(packageReferenceFiles.Item2)) { return(new PackageReferenceFile(packageReferenceFiles.Item2)); } return(null); }
/// <summary> /// Search for packages using the searchText. /// </summary> /// <param name="windowFrame">A window frame that hosts the PackageManagerControl.</param> /// <param name="searchText">Search text.</param> // private void Search(System.Windows.Window windowFrame, string searchText) private void Search(vsShellInterop.IVsWindowFrame windowFrame, string searchText) { ThreadHelper.ThrowIfNotOnUIThread(); if (string.IsNullOrWhiteSpace(searchText)) { return; } var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame); if (packageManagerControl != null) { packageManagerControl.Search(searchText); } }
int IVsTrackProjectRetargetingEvents.OnRetargetingAfterChange(string projRef, IVsHierarchy pAfterChangeHier, string fromTargetFramework, string toTargetFramework) { _errorListProvider.Tasks.Clear(); Project retargetedProject = VsUtility.GetProjectFromHierarchy(pAfterChangeHier); if (retargetedProject != null) { IList <IPackage> packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(retargetedProject); if (!packagesToBeReinstalled.IsEmpty()) { ShowRetargetingErrorTask(packagesToBeReinstalled.Select(p => p.Id), pAfterChangeHier, TaskErrorCategory.Error, TaskPriority.High); } ProjectRetargetingUtility.MarkPackagesForReinstallation(retargetedProject, packagesToBeReinstalled); } return(VSConstants.S_OK); }
/// <summary> /// Returns a list of package references that were marked for reinstallation in packages.config of the project /// </summary> internal static IList <PackageReference> GetPackageReferencesMarkedForReinstallation(Project project) { Debug.Assert(project != null); // First call to VsUtility.PackageConfigExists(project) checks if there is a packages.config file under the project folder, Otherwise, return emtpy list // If present, then call VsUtility.IsNuGetInUse to see if NuGet is used in the project. The second call might result in loading of NuGet.VisualStudio.dll if (VsUtility.PackagesConfigExists(project) && project.IsNuGetInUse()) { PackageReferenceFile packageReferenceFile = GetPackageReferenceFile(project); Debug.Assert(packageReferenceFile != null); IEnumerable <PackageReference> packageReferences = packageReferenceFile.GetPackageReferences(); return(packageReferences.Where(p => p.RequireReinstallation).ToList()); } return(new List <PackageReference>()); }
int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger) { Debug.Assert(pHierarchy != null); Project upgradedProject = VsUtility.GetProjectFromHierarchy(pHierarchy); if (upgradedProject != null) { IList <IPackage> packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedProject); if (!packagesToBeReinstalled.IsEmpty()) { pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name, String.Format(CultureInfo.CurrentCulture, Resources.ProjectUpgradeAndRetargetErrorMessage, String.Join(", ", packagesToBeReinstalled.Select(p => p.Id)))); } } return(VSConstants.S_OK); }
public PackageReferenceFileList(Solution solution) { _projectPackageReferenceFiles = new List <ProjectPackageReferenceFile>(); var packageReferenceFileName = Path.Combine( VsUtility.GetNuGetSolutionFolder(solution), VsUtility.PackageReferenceFile); if (File.Exists(packageReferenceFileName)) { _solutionPackageReferenceFile = packageReferenceFileName; } foreach (Project project in solution.Projects) { GetPackageReferenceFiles(project); } }
private async Task <IVsWindowFrame> FindExistingSolutionWindowFrameAsync() { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var uiShell = await _asyncServiceProvider.GetServiceAsync <SVsUIShell, IVsUIShell>(); foreach (var windowFrame in VsUtility.GetDocumentWindows(uiShell)) { object property; var hr = windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out property); var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame); if (hr == VSConstants.S_OK && property is IVsSolution && packageManagerControl != null) { return(windowFrame); } } return(null); }
private void PackageRestore(ProjectPackageReferenceFile projectPackageReferenceFile) { if (HasCanceled()) { return; } var repoSettings = ServiceLocator.GetInstance <IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); var projectName = projectPackageReferenceFile.Project.GetName(); try { WriteLine(VerbosityLevel.Normal, Resources.RestoringPackagesForProject, projectName); WriteLine(VerbosityLevel.Detailed, Resources.RestoringPackagesListedInFile, projectPackageReferenceFile.FullPath); RestorePackages(projectPackageReferenceFile.FullPath, fileSystem); } catch (Exception ex) { var exceptionMessage = _msBuildOutputVerbosity >= (int)VerbosityLevel.Detailed ? ex.ToString() : ex.Message; var message = String.Format( CultureInfo.CurrentCulture, Resources.PackageRestoreFailedForProject, projectName, exceptionMessage); WriteLine(VerbosityLevel.Quiet, message); ActivityLog.LogError(LogEntrySource, message); VsUtility.ShowError(_errorListProvider, TaskErrorCategory.Error, TaskPriority.High, message, hierarchyItem: null); _hasError = true; } finally { WriteLine(VerbosityLevel.Normal, Resources.PackageRestoreFinishedForProject, projectName); } }
public void GetFullPathOfUnloadedProject() { // Arrange var solution = new Mock <Solution>(); solution.SetupGet(s => s.FullName).Returns(@"c:\a\s.sln"); var dte = new Mock <DTE>(); dte.SetupGet(d => d.Solution).Returns(solution.Object); var project = new Mock <Project>(); project.SetupGet(p => p.DTE).Returns(dte.Object); project.SetupGet(p => p.UniqueName).Returns(@"b\c.csproj"); project.SetupGet(p => p.Kind).Returns(VsConstants.UnloadedProjectTypeGuid); // Act var projectDirectory = VsUtility.GetFullPath(project.Object); // Assert Assert.Equal(@"c:\a\b", projectDirectory); }
public void GetFullPathFallback(string propName, string propValue, string expected) { // Arrange var solution = new Mock <Solution>(); solution.SetupGet(s => s.FullName).Returns(@"c:\a\s.sln"); var dte = new Mock <DTE>(); dte.SetupGet(d => d.Solution).Returns(solution.Object); var property = new Mock <EnvDTE.Property>(); property.SetupGet(p => p.Value).Returns(propValue); var properties = new Mock <EnvDTE.Properties>(); properties.Setup(p => p.Item(propName)).Returns(property.Object); var project = new Mock <Project>(); project.SetupGet(p => p.DTE).Returns(dte.Object); project.SetupGet(p => p.UniqueName).Returns(@"b\c.csproj"); project.SetupGet(p => p.Kind).Returns(VsConstants.CsharpProjectTypeGuid); project.SetupGet(p => p.Properties).Returns(properties.Object); if (propName == "FullName") { project.SetupGet(p => p.FullName).Returns(propValue); } // Act var projectDirectory = VsUtility.GetFullPath(project.Object); // Assert Assert.Equal(@"c:\a\b", projectDirectory); }
/// <summary> /// Returns true if the solution is using the old style package restore. /// </summary> /// <param name="solution">The solution to check.</param> /// <returns>True if the solution is using the old style package restore.</returns> private static bool UsingOldPackageRestore(Solution solution) { var nugetSolutionFolder = VsUtility.GetNuGetSolutionFolder(solution); return(File.Exists(Path.Combine(nugetSolutionFolder, "nuget.targets"))); }
bool RoadInfoCallback(IntPtr callbackData , double carSimX0 , double carSimY0 , double carSimZ0 , double carSimX1 , double carSimY1 , double carSimZ1 , ref BestMedia.VsDotnet.vs_vehicle.VsRoadInfo out_roadInfo) { bool retSuccess = false; var MovementComponent = VsUtility.ToObject(callbackData) as CarSimMovementComponent; Vector3 StartVect = VsUnityLib.VSToUnityVector(carSimX0, carSimY0, carSimZ0); Vector3 EndVect = VsUnityLib.VSToUnityVector(carSimX1, carSimY1, carSimZ1); Vector3 DirVect = EndVect - StartVect; DirVect.Normalize(); Ray ray = new Ray(StartVect, DirVect); RaycastHit HitResult; bool roadPointFound = Physics.Raycast(ray, out HitResult, (StartVect - EndVect).magnitude, RayLayerMask, QueryTriggerInteraction.Ignore); if (DebugShowRay) { Debug.DrawRay(ray.origin, ray.direction * (StartVect - EndVect).magnitude, Color.red, 0.1f); } if (!roadPointFound) { Check(retSuccess == false); } else { if (HitResult.normal.y == 0) { Check(retSuccess == false); } else { HitResult.point.UnityToVSVector(ref out_roadInfo.mCarSimLocX, ref out_roadInfo.mCarSimLocY, ref out_roadInfo.mCarSimLocZ); double nx = 0, ny = 0, nz = 0; HitResult.normal.UnityToVSVector(ref nx, ref ny, ref nz); out_roadInfo.mCarSimDzDx = nz / nx; out_roadInfo.mCarSimDzDy = nz / ny; if (HitResult.collider != null && HitResult.collider.material != null) { out_roadInfo.mCarSimMu = HitResult.collider.material.dynamicFriction; } else { out_roadInfo.mCarSimMu = 0.85f; } out_roadInfo.mCollisionInfo = IntPtr.Zero; retSuccess = true; } } return(retSuccess); }