private void ResolveFiles_1(string[] searchPaths) { if (_assemblyReferences != null) { foreach (AssemblyReference a in _assemblyReferences) { if (!a.IsPrerequisite || a.AssemblyIdentity == null) { if (!ResolveAssembly(a, searchPaths)) { if (_treatUnfoundNativeAssembliesAsPrerequisites && a.ReferenceType == AssemblyReferenceType.NativeAssembly) { a.IsPrerequisite = true; } else { // When we're only reading a manifest (i.e. from ResolveNativeReference task), it's // very useful to report what manifest has the unresolvable reference. However, when // we're generating a new manifest (i.e. from GenerateApplicationManifest task) // reporting the manifest is awkward and sometimes looks like a bug. // So we use the ReadOnly flag to tell the difference between the two cases... if (_readOnly) { OutputMessages.AddErrorMessage("GenerateManifest.ResolveFailedInReadOnlyMode", a.ToString(), this.ToString()); } else { OutputMessages.AddErrorMessage("GenerateManifest.ResolveFailedInReadWriteMode", a.ToString()); } } } } } } }
private void ResolveFiles_2(string[] searchPaths) { if (_fileReferences != null) { foreach (FileReference f in _fileReferences) { if (!ResolveFile(f, searchPaths)) { // When we're only reading a manifest (i.e. from ResolveNativeReference task), it's // very useful to report what manifest has the unresolvable reference. However, when // we're generating a new manifest (i.e. from GenerateApplicationManifest task) // reporting the manifest is awkward and sometimes looks like a bug. // So we use the ReadOnly flag to tell the difference between the two cases... if (_readOnly) { OutputMessages.AddErrorMessage("GenerateManifest.ResolveFailedInReadOnlyMode", f.ToString(), this.ToString()); } else { OutputMessages.AddErrorMessage("GenerateManifest.ResolveFailedInReadWriteMode", f.ToString()); } } } } }
private void ValidateReferencesForNativeApplication() { foreach (AssemblyReference assembly in AssemblyReferences) { // Check that the assembly identity matches the filename for all local dependencies... if (!assembly.IsPrerequisite && !String.Equals(assembly.AssemblyIdentity.Name, Path.GetFileNameWithoutExtension(assembly.TargetPath), StringComparison.OrdinalIgnoreCase)) { OutputMessages.AddErrorMessage("GenerateManifest.IdentityFileNameMismatch", assembly.ToString(), assembly.AssemblyIdentity.Name, assembly.AssemblyIdentity.Name + Path.GetExtension(assembly.TargetPath)); } } }
private void ValidateEntryPoint() { if (_entryPoint != null) { bool isCorrectFileType = !String.IsNullOrEmpty(_entryPoint.TargetPath) && _entryPoint.TargetPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase); if (!isCorrectFileType) { OutputMessages.AddErrorMessage("GenerateManifest.InvalidEntryPoint", _entryPoint.ToString()); } } }
private void ValidateMinimumRequiredVersion() { if (!String.IsNullOrEmpty(_minimumRequiredVersion)) { Version v1 = new Version(_minimumRequiredVersion); Version v2 = new Version(AssemblyIdentity.Version); if (v1 > v2) { OutputMessages.AddErrorMessage("GenerateManifest.GreaterMinimumRequiredVersion"); } } }
/// <summary> /// Implementation of UpdateFileInfo /// </summary> /// <param name="targetFrameworkVersion">null, if not TFV. If no TFV, it will use sha256 signature algorithm.</param> private void UpdateFileInfoImpl(string targetFrameworkVersion) { if (_assemblyReferences != null) { foreach (AssemblyReference a in _assemblyReferences) { if (!String.IsNullOrEmpty(a.ResolvedPath)) // only check resolved items... { try { UpdateAssemblyReference(a, targetFrameworkVersion); if (a.AssemblyIdentity == null) { BadImageFormatException exception = new BadImageFormatException(null, a.ResolvedPath); OutputMessages.AddErrorMessage("GenerateManifest.General", exception.Message); } } catch (System.Exception e) { OutputMessages.AddErrorMessage("GenerateManifest.General", e.Message); } } } } if (_fileReferences != null) { foreach (FileReference f in _fileReferences) { if (!String.IsNullOrEmpty(f.ResolvedPath)) // only check resolved items... { try { UpdateFileReference(f, targetFrameworkVersion); } catch (System.Exception e) { OutputMessages.AddErrorMessage("GenerateManifest.General", e.Message); } } } } }
private void ValidateEntryPoint() { if (_entryPoint != null) { if (!String.IsNullOrEmpty(_entryPoint.TargetPath) && !_entryPoint.TargetPath.EndsWith(".manifest", StringComparison.OrdinalIgnoreCase)) { OutputMessages.AddErrorMessage("GenerateManifest.InvalidEntryPoint", _entryPoint.ToString()); } string ManifestPath = _entryPoint.ResolvedPath; if (ManifestPath == null) { ManifestPath = Path.Combine(Path.GetDirectoryName(SourcePath), _entryPoint.TargetPath); } if (File.Exists(ManifestPath)) { ApplicationManifest entryPointManifest = ManifestReader.ReadManifest(ManifestPath, false) as ApplicationManifest; if (entryPointManifest != null) { if (Install) { if (entryPointManifest.HostInBrowser) { OutputMessages.AddErrorMessage("GenerateManifest.HostInBrowserNotOnlineOnly"); } } else { if (entryPointManifest.FileAssociations != null && entryPointManifest.FileAssociations.Count > 0) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsNotInstalled"); } } } } } }
private void ValidateReferencesForClickOnceApplication() { int t1 = Environment.TickCount; bool isPartialTrust = !TrustInfo.IsFullTrust; Dictionary <string, NGen <bool> > targetPathList = new Dictionary <string, NGen <bool> >(); foreach (AssemblyReference assembly in AssemblyReferences) { // Check all resolved dependencies for partial trust apps... if (isPartialTrust && (assembly != EntryPoint) && !String.IsNullOrEmpty(assembly.ResolvedPath)) { ValidateReferenceForPartialTrust(assembly, TrustInfo); } // Check TargetPath for all local dependencies, ignoring any Prerequisites if (!assembly.IsPrerequisite && !String.IsNullOrEmpty(assembly.TargetPath)) { // Check target path does not exceed maximum... if (_maxTargetPath > 0 && assembly.TargetPath.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.ToString(), _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } // Check for two or more items with the same TargetPath... string key = assembly.TargetPath.ToLowerInvariant(); if (!targetPathList.ContainsKey(key)) { targetPathList.Add(key, false); } else if (targetPathList[key] == false) { OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", assembly.ToString()); targetPathList[key] = true; // only warn once per path } } else { // Check assembly name does not exceed maximum... if (_maxTargetPath > 0 && assembly.AssemblyIdentity.Name.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.AssemblyIdentity.Name, _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } } // Check that all prerequisites are strong named... if (assembly.IsPrerequisite && !assembly.AssemblyIdentity.IsStrongName && !assembly.IsVirtual) { OutputMessages.AddErrorMessage("GenerateManifest.PrerequisiteNotSigned", assembly.ToString()); } } foreach (FileReference file in FileReferences) { // Check that file is not an assembly... if (!String.IsNullOrEmpty(file.ResolvedPath) && PathUtil.IsAssembly(file.ResolvedPath)) { OutputMessages.AddWarningMessage("GenerateManifest.AssemblyAsFile", file.ToString()); } if (!String.IsNullOrEmpty(file.TargetPath)) { // Check target path does not exceed maximum... if (_maxTargetPath > 0 && file.TargetPath.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", file.TargetPath, _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } // Check for two or more items with the same TargetPath... string key = file.TargetPath.ToLowerInvariant(); if (!targetPathList.ContainsKey(key)) { targetPathList.Add(key, false); } else if (targetPathList[key] == false) { OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", file.TargetPath); targetPathList[key] = true; // only warn once per path } } } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckManifestReferences t={0}", Environment.TickCount - t1)); }
private void ValidateFileAssociations() { if (FileAssociations.Count > 0) { if (FileAssociations.Count > Constants.MaxFileAssociationsCount) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsCountExceedsMaximum", Constants.MaxFileAssociationsCount.ToString(CultureInfo.CurrentUICulture)); } Dictionary <string, FileAssociation> usedExtensions = new Dictionary <string, FileAssociation>(StringComparer.OrdinalIgnoreCase); foreach (FileAssociation fileAssociation in FileAssociations) { if (string.IsNullOrEmpty(fileAssociation.Extension) || string.IsNullOrEmpty(fileAssociation.Description) || string.IsNullOrEmpty(fileAssociation.ProgId) || string.IsNullOrEmpty(fileAssociation.DefaultIcon)) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationMissingAttribute"); } if (!string.IsNullOrEmpty(fileAssociation.Extension)) { if (fileAssociation.Extension[0] != '.') { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationExtensionMissingLeadDot"); } if (fileAssociation.Extension.Length > Constants.MaxFileAssociationExtensionLength) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationExtensionTooLong", fileAssociation.Extension, Constants.MaxFileAssociationExtensionLength.ToString(CultureInfo.CurrentUICulture)); } if (!usedExtensions.ContainsKey(fileAssociation.Extension)) { usedExtensions.Add(fileAssociation.Extension, fileAssociation); } else { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsDuplicateExtensions", fileAssociation.Extension); } } if (!string.IsNullOrEmpty(fileAssociation.DefaultIcon)) { FileReference defaultIconReference = null; foreach (FileReference fileReference in FileReferences) { if (fileReference.TargetPath.Equals(fileAssociation.DefaultIcon, StringComparison.Ordinal)) { defaultIconReference = fileReference; break; } } if (defaultIconReference == null || !string.IsNullOrEmpty(defaultIconReference.Group)) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationDefaultIconNotInstalled", fileAssociation.DefaultIcon); } } } if (!TrustInfo.IsFullTrust) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsApplicationNotFullTrust"); } if (EntryPoint == null) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsNoEntryPoint"); } } }
private void ValidateCom() { int t1 = Environment.TickCount; string outputFileName = Path.GetFileName(SourcePath); Dictionary <string, ComInfo> clsidList = new Dictionary <string, ComInfo>(); Dictionary <string, ComInfo> tlbidList = new Dictionary <string, ComInfo>(); // Check for duplicate COM definitions in all dependent manifests... foreach (AssemblyReference assembly in AssemblyReferences) { if (assembly.ReferenceType == AssemblyReferenceType.NativeAssembly && !assembly.IsPrerequisite && !String.IsNullOrEmpty(assembly.ResolvedPath)) { ComInfo[] comInfoArray = ManifestReader.GetComInfo(assembly.ResolvedPath);; if (comInfoArray != null) { foreach (ComInfo comInfo in comInfoArray) { if (!String.IsNullOrEmpty(comInfo.ClsId)) { string key = comInfo.ClsId.ToLowerInvariant(); if (!clsidList.ContainsKey(key)) { clsidList.Add(key, comInfo); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "clsid", comInfo.ComponentFileName, comInfo.ClsId, comInfo.ManifestFileName, clsidList[key].ManifestFileName); } } if (!String.IsNullOrEmpty(comInfo.TlbId)) { string key = comInfo.TlbId.ToLowerInvariant(); if (!tlbidList.ContainsKey(key)) { tlbidList.Add(key, comInfo); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "tlbid", comInfo.ComponentFileName, comInfo.TlbId, comInfo.ManifestFileName, tlbidList[key].ManifestFileName); } } } } } } // Check for duplicate COM definitions in the manifest about to be generated... foreach (FileReference file in FileReferences) { if (file.ComClasses != null) { foreach (ComClass comClass in file.ComClasses) { string key = comClass.ClsId.ToLowerInvariant(); if (!clsidList.ContainsKey(key)) { clsidList.Add(key, new ComInfo(outputFileName, file.TargetPath, comClass.ClsId, null)); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "clsid", file.ToString(), comClass.ClsId, outputFileName, clsidList[key].ManifestFileName); } } } if (file.TypeLibs != null) { foreach (TypeLib typeLib in file.TypeLibs) { string key = typeLib.TlbId.ToLowerInvariant(); if (!tlbidList.ContainsKey(key)) { tlbidList.Add(key, new ComInfo(outputFileName, file.TargetPath, null, typeLib.TlbId)); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "tlbid", file.ToString(), typeLib.TlbId, outputFileName, tlbidList[key].ManifestFileName); } } } } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckForComDuplicates t={0}", Environment.TickCount - t1)); }