public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; Dictionary <string, string> referencesInProject = dteHelper.GetReferences(); ZipPackage zipPackage = new ZipPackage(packageFullPath); List <FrameworkAssemblyReference> frameworkAssemblies = zipPackage.FrameworkAssemblies.ToList(); if (frameworkAssemblies == null || frameworkAssemblies.Count == 0) { outputBuilder.Append("No Framework assemblies present in the package. Skipping the verification."); return(null); } //Get only thr framework assemblies which applies to the current project. frameworkAssemblies = frameworkAssemblies.Where(item => item.SupportedFrameworks.Contains(new FrameworkName(dteHelper.GetProjectFramework()))).ToList(); foreach (FrameworkAssemblyReference frameworkassembly in frameworkAssemblies) { if (!referencesInProject.Keys.Contains(frameworkassembly.AssemblyName)) { HasSuceeded = false; errorBuilder.AppendFormat(" Reference to the Framework Assembly {0} not added to the project. Check the solution @ {1} for more details.", frameworkassembly.AssemblyName, solutionPath); errorBuilder.AppendLine(); } else { outputBuilder.AppendFormat(" Reference to the Framework Assembly {0} added properly.", frameworkassembly.AssemblyName); outputBuilder.AppendLine(); } } return(HasSuceeded); }
/// <summary> /// Validates the expected references to be added by the given package and the actual references being added matches. /// </summary> /// <param name="packageFullPath"></param> /// <param name="solutionPath"></param> public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { ZipPackage zipPackage = new ZipPackage(packageFullPath); if (zipPackage.IsSatellitePackage()) { return(null); } string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; Dictionary <string, string> referencesInProject = dteHelper.GetReferences(); string packageId = zipPackage.Id; List <IPackageFile> files = zipPackage.GetLibFiles().ToList(); if (files == null || files.Count == 0) { outputBuilder.AppendFormat(" No Lib files are present in the nupkg file.Skipping reference validation."); return(null); } //Get compatible items for the current project. //if no compatible items, then check if there are any files with directly under Lib and get them. IEnumerable <IPackageFile> compatibleItems; VersionUtility.TryGetCompatibleItems(new FrameworkName(dteHelper.GetProjectFramework()), files, out compatibleItems); if (compatibleItems == null || compatibleItems.ToList().Count == 0) { VersionUtility.TryGetCompatibleItems(null, files, out compatibleItems); } if (compatibleItems == null || compatibleItems.ToList().Count == 0) { outputBuilder.AppendFormat(" The package doesnt have a Lib folder matching the current project's target framework : {0}", dteHelper.GetProjectFramework()); return(null); } //Check that the compatible lib files are added as references. foreach (IPackageFile file in compatibleItems) { if (file.Path.EndsWith(".dll") || file.Path.EndsWith(".exe")) //exclude xml files { string referenceName = Path.GetFileNameWithoutExtension((file.Path)); if (!referencesInProject.Keys.Contains(referenceName, StringComparer.OrdinalIgnoreCase)) { HasSuceeded = false; errorBuilder.AppendFormat("The reference {0} is not added to project as part of installating package {1}.Check the Solution @ {2} for details", referenceName, packageId, solutionPath); errorBuilder.AppendLine(); } else { outputBuilder.AppendFormat("Reference Added properly for Lib : {0} !!", file.Path); outputBuilder.AppendLine(); } } } return(HasSuceeded); }
/// <summary> /// Validates that the reference corrresponding to the resource assembly is added to the project and the resources are being extracted. /// </summary> /// <param name="packageFullPath"></param> /// <param name="solutionPath"></param> public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { ZipPackage zipPackage = new ZipPackage(packageFullPath); string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; if (zipPackage.IsSatellitePackage()) { string language = zipPackage.Language; List <IPackageFile> satelliteFiles = zipPackage.GetSatelliteFiles().ToList(); foreach (IPackageFile satelliteFile in satelliteFiles) { if (satelliteFile.Path.EndsWith(".dll") || satelliteFile.Path.EndsWith(".exe")) //exclude xml files { string satelliteAssembly = Path.GetFileNameWithoutExtension(satelliteFile.Path); string baseAssemblyName = satelliteAssembly.Replace(".resources", ""); //base assembly name would be the same without ".resources" Reference baseReference = (Reference)dteHelper.GetReferenceByName(baseAssemblyName); if (baseReference == null) { HasSuceeded = false; errorBuilder.AppendFormat(" No reference added for the ENU assembly {0} relative to the satellite assembly {1}.", baseAssemblyName, satelliteAssembly); errorBuilder.AppendLine(); } else { string expectedSatelliteAssemblyPath = (Path.Combine(Path.GetDirectoryName(baseReference.Path), language, satelliteAssembly + ".dll")); if (File.Exists(expectedSatelliteAssemblyPath)) { outputBuilder.AppendFormat("Reference added for ENU assembly {0} and the resources are extraced next to it @ {1}", baseAssemblyName, expectedSatelliteAssemblyPath); outputBuilder.AppendLine(); } else { HasSuceeded = false; errorBuilder.AppendFormat("The satellite assembly is not extraced @ {0} for reference {1}", expectedSatelliteAssemblyPath, baseAssemblyName); errorBuilder.AppendLine(); } } } } } else { return(null); } return(HasSuceeded); }
bool?IPackageVerifier.Validate(string packageFullPath, VsProjectManager dteHelper) { var reference = dteHelper.GetActiveProject().Object.References.Item("Nuget.VisualStudio"); if (reference == null) { errorBuilder.Append("Reference to Nuget.visualStudio not added to the project."); return(false); } if (reference.EmbedInteropTypes == true) { outputBuilder.Append("Reference to Nuget.VisualStudio has EmbedInterOpTypes set to true properly"); return(true); } else { errorBuilder.Append("Reference to Nuget.VisualStudio doesn't have EmbedInterOpTypes set to True as expected."); return(false); } }
public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; ZipPackage zipPackage = new ZipPackage(packageFullPath); List <IPackageFile> files = zipPackage.GetContentFiles().ToList(); if (files == null || files.Count == 0) { outputBuilder.AppendFormat(" No content files are present in the nupkg file.Skipping content validation"); return(null); } //Get compatible items for the current project. //if no compatible items, then check if there are any files with directly under contents and get them. IEnumerable <IPackageFile> compatibleItems; VersionUtility.TryGetCompatibleItems(new FrameworkName(dteHelper.GetProjectFramework()), files, out compatibleItems); if (compatibleItems == null || compatibleItems.ToList().Count == 0) { VersionUtility.TryGetCompatibleItems(null, files, out compatibleItems); } if (compatibleItems == null || compatibleItems.ToList().Count == 0) { outputBuilder.AppendFormat(" The package doesnt have a content folder matching the current project's target framework : {0}", dteHelper.GetProjectFramework()); return(null); } //exclude the .transform files as they are treated separeately. List <IPackageFile> contentFiles = new List <IPackageFile>(); foreach (IPackageFile file in compatibleItems) { if (!file.Path.EndsWith(".transform")) { contentFiles.Add(file); } } if (contentFiles == null || contentFiles.Count == 0) { outputBuilder.AppendFormat(" No content files are present in the nupkg file.Skipping content validation"); return(null); } foreach (IPackageFile file in contentFiles) { string filePath = file.Path.Remove(0, @"Content\".Length); if (file.Path.EndsWith(".pp")) { filePath = filePath.Remove(filePath.Length - 3, 3); } filePath = Path.Combine(solutionPath, filePath); if (File.Exists(filePath)) { outputBuilder.AppendFormat("Content file : {0} added properly !!", file.Path); outputBuilder.AppendLine(); } else { HasSuceeded = false; errorBuilder.AppendFormat("Content file : {0} not added properly. Check the solution @ {1} for more details", file.Path, solutionPath); errorBuilder.AppendLine(); } } return(HasSuceeded); }