bool IComReferenceResolver.ResolveComClassicReference(System.Runtime.InteropServices.ComTypes.TYPELIBATTR typeLibAttr, string outputDirectory, string wrapperType, string refName, out ComReferenceWrapperInfo wrapperInfo)
 {
     ComReferenceInfo info;
     bool topLevelRef = false;
     wrapperInfo = null;
     System.Runtime.InteropServices.ComTypes.TYPELIBATTR typelibattr = typeLibAttr;
     if (ComReference.RemapAdoTypeLib(base.Log, ref typeLibAttr))
     {
         base.Log.LogMessageFromResources(MessageImportance.Low, "ResolveComReference.RemappingAdoTypeLib", new object[] { typelibattr.wMajorVerNum, typelibattr.wMinorVerNum });
     }
     if (this.IsExistingProjectReference(typeLibAttr, wrapperType, out info))
     {
         topLevelRef = true;
         wrapperType = info.taskItem.GetMetadata("WrapperTool");
     }
     else if (this.IsExistingDependencyReference(typeLibAttr, out info))
     {
         if ((wrapperType == null) || ComReferenceTypes.IsPiaOrTlbImp(wrapperType))
         {
             string key = ComReference.UniqueKeyFromTypeLibAttr(typeLibAttr);
             if (this.cachePia.ContainsKey(key))
             {
                 wrapperType = "primary";
             }
             else if (this.cacheTlb.ContainsKey(key))
             {
                 wrapperType = "tlbimp";
             }
         }
     }
     else
     {
         try
         {
             info = new ComReferenceInfo();
             if (info.InitializeWithTypeLibAttrs(base.Log, typeLibAttr, null, this.TargetProcessorArchitecture))
             {
                 this.allDependencyRefs.Add(info);
             }
             else
             {
                 info.ReleaseTypeLibPtr();
                 return false;
             }
         }
         catch (COMException exception)
         {
             base.Log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLib", new object[] { typeLibAttr.guid, typeLibAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture), typeLibAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture), exception.Message });
             info.ReleaseTypeLibPtr();
             return false;
         }
     }
     if (refName == null)
     {
         refName = info.typeLibName;
     }
     return this.ResolveComClassicReference(info, outputDirectory, wrapperType, refName, topLevelRef, info.dependentWrapperPaths, out wrapperInfo);
 }
コード例 #2
0
ファイル: ResolveComReference.cs プロジェクト: nikson/msbuild
        /*
         * Method:  ConvertAttrReferencesToComReferenceInfo
         * 
         * Helper method. Converts TypeLibAttr references to ComReferenceInfo objects.
         * This method cannot fail, since we want to proceed with the task even if some references won't load.
         */
        private void ConvertAttrReferencesToComReferenceInfo(List<ComReferenceInfo> projectRefs, ITaskItem[] typeLibAttrs)
        {
            int typeLibAttrsLength = (typeLibAttrs == null) ? 0 : typeLibAttrs.GetLength(0);

            for (int i = 0; i < typeLibAttrsLength; i++)
            {
                ComReferenceInfo projectRefInfo = new ComReferenceInfo();

                try
                {
                    if (projectRefInfo.InitializeWithTypeLibAttrs(Log, Silent, TaskItemToTypeLibAttr(typeLibAttrs[i]), typeLibAttrs[i], this.TargetProcessorArchitecture))
                    {
                        projectRefs.Add(projectRefInfo);
                    }
                    else
                    {
                        projectRefInfo.ReleaseTypeLibPtr();
                    }
                }
                catch (COMException ex)
                {
                    if (!Silent)
                    {
                        Log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLibItemSpec", typeLibAttrs[i].ItemSpec, ex.Message);
                    }

                    projectRefInfo.ReleaseTypeLibPtr();
                    // we don't want to fail the task if one of the references is not registered, so just continue
                }
            }
        }
 private void ConvertAttrReferencesToComReferenceInfo(List<ComReferenceInfo> projectRefs, ITaskItem[] typeLibAttrs)
 {
     int num = (typeLibAttrs == null) ? 0 : typeLibAttrs.GetLength(0);
     for (int i = 0; i < num; i++)
     {
         ComReferenceInfo item = new ComReferenceInfo();
         try
         {
             if (item.InitializeWithTypeLibAttrs(base.Log, TaskItemToTypeLibAttr(typeLibAttrs[i]), typeLibAttrs[i], this.TargetProcessorArchitecture))
             {
                 projectRefs.Add(item);
             }
             else
             {
                 item.ReleaseTypeLibPtr();
             }
         }
         catch (COMException exception)
         {
             base.Log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLibItemSpec", new object[] { typeLibAttrs[i].ItemSpec, exception.Message });
             item.ReleaseTypeLibPtr();
         }
     }
 }
コード例 #4
0
ファイル: ResolveComReference.cs プロジェクト: nikson/msbuild
        /*
         * Method:  ResolveComClassicReference
         * 
         * Resolves a COM classic reference given the type library attributes and the type of wrapper to use.
         * If wrapper type is not specified, this method will first look for an existing reference in the project,
         * fall back to looking for a PIA and finally try to generate a regular tlbimp wrapper.
         *
         * This is the method available for references to call back to resolve their dependencies
         */
        bool IComReferenceResolver.ResolveComClassicReference(TYPELIBATTR typeLibAttr, string outputDirectory, string wrapperType, string refName, out ComReferenceWrapperInfo wrapperInfo)
        {
            // does this reference exist in the project or is it a dependency?
            bool topLevelRef = false;

            wrapperInfo = null;

            // remap the type lib to ADO 2.7 if necessary
            TYPELIBATTR oldAttr = typeLibAttr;

            if (ComReference.RemapAdoTypeLib(Log, Silent, ref typeLibAttr) && !Silent)
            {
                // if successfully remapped the reference to ADO 2.7, notify the user
                Log.LogMessageFromResources(MessageImportance.Low, "ResolveComReference.RemappingAdoTypeLib", oldAttr.wMajorVerNum, oldAttr.wMinorVerNum);
            }

            ComReferenceInfo referenceInfo;

            // find an existing ref in the project (taking the desired wrapperType into account, if any)
            if (IsExistingProjectReference(typeLibAttr, wrapperType, out referenceInfo))
            {
                // IsExistingProjectReference should not return null... 
                Debug.Assert(referenceInfo != null, "IsExistingProjectReference should not return null");
                topLevelRef = true;
                wrapperType = referenceInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.wrapperTool);
            }
            // was this dependency already processed?
            else if (IsExistingDependencyReference(typeLibAttr, out referenceInfo))
            {
                Debug.Assert(referenceInfo != null, "IsExistingDependencyReference should not return null");

                // we've seen this dependency before, so we should know what its wrapper type is.
                if (wrapperType == null || ComReferenceTypes.IsPiaOrTlbImp(wrapperType))
                {
                    string typeLibKey = ComReference.UniqueKeyFromTypeLibAttr(typeLibAttr);
                    if (_cachePia.ContainsKey(typeLibKey))
                    {
                        wrapperType = ComReferenceTypes.primary;
                    }
                    else if (_cacheTlb.ContainsKey(typeLibKey))
                    {
                        wrapperType = ComReferenceTypes.tlbimp;
                    }
                }
            }
            // if not found anywhere, create a new ComReferenceInfo object and resolve it.
            else
            {
                try
                {
                    referenceInfo = new ComReferenceInfo();

                    if (referenceInfo.InitializeWithTypeLibAttrs(Log, Silent, typeLibAttr, null, this.TargetProcessorArchitecture))
                    {
                        allDependencyRefs.Add(referenceInfo);
                    }
                    else
                    {
                        referenceInfo.ReleaseTypeLibPtr();
                        return false;
                    }
                }
                catch (COMException ex)
                {
                    if (!Silent)
                    {
                        Log.LogWarningWithCodeFromResources("ResolveComReference.CannotLoadTypeLib", typeLibAttr.guid,
                            typeLibAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture),
                            typeLibAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture),
                            ex.Message);
                    }

                    referenceInfo.ReleaseTypeLibPtr();

                    // can't resolve an unregistered and unknown dependency, so return false
                    return false;
                }
            }

            // if we don't have the reference name, use the typelib name
            if (refName == null)
            {
                refName = referenceInfo.typeLibName;
            }

            return ResolveComClassicReference(referenceInfo, outputDirectory, wrapperType, refName, topLevelRef, referenceInfo.dependentWrapperPaths, out wrapperInfo);
        }