private string ConvertTransformFlagsToCommandLineCommand(ResolveComReference.TlbImpTransformFlags flags) { switch (flags) { case ResolveComReference.TlbImpTransformFlags.None: return null; case ResolveComReference.TlbImpTransformFlags.TransformDispRetVals: return "DispRet"; case ResolveComReference.TlbImpTransformFlags.SerializableValueClasses: return "SerializableValueClasses"; } return null; }
private ResolveComReference.TlbImpTransformFlags GetTlbImpTransformFlagsParameterWithDefault(string parameterName, ResolveComReference.TlbImpTransformFlags defaultValue) { object obj2 = base.Bag[parameterName]; if (obj2 != null) { return (ResolveComReference.TlbImpTransformFlags) obj2; } return defaultValue; }
public void MultiTargetingDefaultSetCorrectly() { ResolveComReference t = new ResolveComReference(); Assert.IsTrue(t.ExecuteAsTool, "ExecuteAsTool should default to true"); }
/// <summary> /// Helper method that will new up an AX and matching TLB reference, and verify that the AX reference /// sets its RCW appropriately. /// </summary> private void CheckAxReferenceRCWTlbExists(RcwStyle rcwStyle, bool includeVersionInInteropName) { Guid axGuid = Guid.NewGuid(); ComReferenceInfo tlbRefInfo; ResolveComReference rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); rcr.IncludeVersionInInteropName = includeVersionInInteropName; rcr.allProjectRefs = new List<ComReferenceInfo>(); TaskItem axTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.aximp); ComReferenceInfo axRefInfo = CreateComReferenceInfo(axTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(axRefInfo); switch (rcwStyle) { case RcwStyle.GenerateTlb: break; case RcwStyle.PreexistingTlb: { TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.tlbimp, "true"); tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(tlbRefInfo); break; } case RcwStyle.PreexistingPia: { TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.primary, "true"); tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(tlbRefInfo); break; } } rcr.AddMissingTlbReferences(); Assert.AreEqual(2, rcr.allProjectRefs.Count, "Should be two references"); tlbRefInfo = (ComReferenceInfo)rcr.allProjectRefs[1]; var embedInteropTypes = tlbRefInfo.taskItem.GetMetadata(ItemMetadataNames.embedInteropTypes); Assert.AreEqual("false", embedInteropTypes, "The tlb wrapper for the activex control should have EmbedInteropTypes=false not " + embedInteropTypes); Assert.IsTrue(ComReference.AreTypeLibAttrEqual(tlbRefInfo.attr, axRefInfo.attr), "reference information should be the same"); Assert.AreEqual ( TlbReference.GetWrapperFileName ( axRefInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName), includeVersionInInteropName, axRefInfo.attr.wMajorVerNum, axRefInfo.attr.wMinorVerNum ), TlbReference.GetWrapperFileName ( tlbRefInfo.typeLibName, includeVersionInInteropName, tlbRefInfo.attr.wMajorVerNum, tlbRefInfo.attr.wMinorVerNum ), "Expected Ax reference's RCW name to match the new TLB" ); }
public void TestCheckForConflictingReferences() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); ResolveComReference rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); // populate the ResolveComReference's list of project references rcr.allProjectRefs = new List<ComReferenceInfo>(); rcr.allProjectRefs.Add(axRefInfo); rcr.allProjectRefs.Add(tlbRefInfo); rcr.allProjectRefs.Add(piaRefInfo); // no conflicts should be found with just the three initial refs Assert.IsTrue(rcr.CheckForConflictingReferences()); Assert.AreEqual(3, rcr.allProjectRefs.Count); ComReferenceInfo referenceInfo; // duplicate refs should not be treated as conflicts referenceInfo = new ComReferenceInfo(tlbRefInfo); rcr.allProjectRefs.Add(referenceInfo); referenceInfo = new ComReferenceInfo(axRefInfo); rcr.allProjectRefs.Add(referenceInfo); referenceInfo = new ComReferenceInfo(piaRefInfo); rcr.allProjectRefs.Add(referenceInfo); Assert.IsTrue(rcr.CheckForConflictingReferences()); Assert.AreEqual(6, rcr.allProjectRefs.Count); // tlb and ax refs with same lib name but different attributes should be considered conflicting // We don't care about typelib name conflicts for PIA refs, because we don't have to create wrappers for them ComReferenceInfo conflictTlb = new ComReferenceInfo(tlbRefInfo); conflictTlb.attr = notInProjectAttr; rcr.allProjectRefs.Add(conflictTlb); ComReferenceInfo conflictAx = new ComReferenceInfo(axRefInfo); conflictAx.attr = notInProjectAttr; rcr.allProjectRefs.Add(conflictAx); ComReferenceInfo piaRef = new ComReferenceInfo(piaRefInfo); piaRef.attr = notInProjectAttr; rcr.allProjectRefs.Add(piaRef); Assert.IsTrue(!rcr.CheckForConflictingReferences()); // ... and conflicting references should have been removed Assert.AreEqual(7, rcr.allProjectRefs.Count); Assert.IsTrue(!rcr.allProjectRefs.Contains(conflictTlb)); Assert.IsTrue(!rcr.allProjectRefs.Contains(conflictAx)); Assert.IsTrue(rcr.allProjectRefs.Contains(piaRef)); }
public void GetResolvedASsemblyReferenceSpecNotNull() { var task = new ResolveComReference(); Assert.IsTrue(null != task.GetResolvedAssemblyReferenceItemSpecs()); }
public void CheckSetCopyLocalToFalseOnEmbedInteropTypesAssemblies() { string gacPath = @"C:\windows\gac"; ResolveComReference rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); // the matrix of TargetFrameworkVersion values we are testing string[] fxVersions = { "v2.0", "v3.0", "v3.5", "v4.0" }; for (int i = 0; i < fxVersions.Length; i++) { string fxVersion = fxVersions[i]; ArrayList taskItems = new ArrayList(); TaskItem nonGacNoPrivate = new TaskItem(@"C:\windows\gar\test1.dll"); nonGacNoPrivate.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); TaskItem gacNoPrivate = new TaskItem(@"C:\windows\gac\assembly1.dll"); gacNoPrivate.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); TaskItem nonGacPrivateFalse = new TaskItem(@"C:\windows\gar\test1.dll"); nonGacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false"); nonGacPrivateFalse.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); TaskItem gacPrivateFalse = new TaskItem(@"C:\windows\gac\assembly1.dll"); gacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false"); gacPrivateFalse.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); TaskItem nonGacPrivateTrue = new TaskItem(@"C:\windows\gar\test1.dll"); nonGacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true"); nonGacPrivateTrue.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); TaskItem gacPrivateTrue = new TaskItem(@"C:\windows\gac\assembly1.dll"); gacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true"); gacPrivateTrue.SetMetadata(ItemMetadataNames.embedInteropTypes, "true"); taskItems.Add(nonGacNoPrivate); taskItems.Add(gacNoPrivate); taskItems.Add(nonGacPrivateFalse); taskItems.Add(gacPrivateFalse); taskItems.Add(nonGacPrivateTrue); taskItems.Add(gacPrivateTrue); rcr.TargetFrameworkVersion = fxVersion; rcr.SetFrameworkVersionFromString(rcr.TargetFrameworkVersion); rcr.SetCopyLocalToFalseOnGacOrNoPIAAssemblies(taskItems, gacPath); bool enabledNoPIA = false; switch (fxVersion) { case "v4.0": enabledNoPIA = true; break; default: break; } // if Private is missing, by default GAC items are CopyLocal=false, non GAC CopyLocal=true Assert.IsTrue ( nonGacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"), fxVersion + ": Non Gac assembly, missing Private" ); Assert.IsTrue ( gacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"), fxVersion + ": Gac assembly, missing Private" ); // if Private is set, it takes precedence Assert.IsTrue ( nonGacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"), fxVersion + ": Non Gac assembly, Private false" ); Assert.IsTrue ( gacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "false"), fxVersion + ": Gac assembly, Private false" ); Assert.IsTrue ( nonGacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"), fxVersion + ": Non Gac assembly, Private true, should be TRUE" ); Assert.IsTrue ( gacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == (enabledNoPIA ? "false" : "true"), fxVersion + ": Gac assembly, Private true, should be TRUE" ); } }
public void CheckSetCopyLocalToFalseOnGacAssemblies() { string gacPath = @"C:\windows\gac"; ResolveComReference rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); ArrayList taskItems = new ArrayList(); TaskItem nonGacNoPrivate = new TaskItem(@"C:\windows\gar\test1.dll"); TaskItem gacNoPrivate = new TaskItem(@"C:\windows\gac\assembly1.dll"); TaskItem nonGacPrivateFalse = new TaskItem(@"C:\windows\gar\test1.dll"); nonGacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false"); TaskItem gacPrivateFalse = new TaskItem(@"C:\windows\gac\assembly1.dll"); gacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false"); TaskItem nonGacPrivateTrue = new TaskItem(@"C:\windows\gar\test1.dll"); nonGacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true"); TaskItem gacPrivateTrue = new TaskItem(@"C:\windows\gac\assembly1.dll"); gacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true"); taskItems.Add(nonGacNoPrivate); taskItems.Add(gacNoPrivate); taskItems.Add(nonGacPrivateFalse); taskItems.Add(gacPrivateFalse); taskItems.Add(nonGacPrivateTrue); taskItems.Add(gacPrivateTrue); rcr.SetCopyLocalToFalseOnGacOrNoPIAAssemblies(taskItems, gacPath); // if Private is missing, by default GAC items are CopyLocal=false, non GAC CopyLocal=true Assert.IsTrue(nonGacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, missing Private, should be TRUE"); Assert.IsTrue(gacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, missing Private, should be FALSE"); // if Private is set, it takes precedence Assert.IsTrue(nonGacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Non Gac assembly, Private false, should be FALSE"); Assert.IsTrue(gacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, Private false, should be FALSE"); Assert.IsTrue(nonGacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, Private true, should be TRUE"); Assert.IsTrue(gacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Gac assembly, Private true, should be TRUE"); }
public void DelaySignWithoutEitherKeyFileOrKeyContainer() { ResolveComReference rcr = new ResolveComReference(); MockEngine e = new MockEngine(); rcr.BuildEngine = e; rcr.DelaySign = true; Assert.IsTrue(!rcr.Execute()); e.AssertLogContains("MSB3301"); }
public void BothKeyFileAndKeyContainer() { ResolveComReference rcr = new ResolveComReference(); MockEngine e = new MockEngine(); rcr.BuildEngine = e; rcr.KeyFile = "foo"; rcr.KeyContainer = "bar"; Assert.IsTrue(!rcr.Execute()); e.AssertLogContains("MSB3300"); }
public void CheckAddMissingTlbReference() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); ResolveComReference rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); // populate the ResolveComReference's list of project references rcr.allProjectRefs = new List<ComReferenceInfo>(); rcr.allProjectRefs.Add(axRefInfo); rcr.allProjectRefs.Add(tlbRefInfo); rcr.allProjectRefs.Add(piaRefInfo); rcr.AddMissingTlbReferences(); Assert.IsTrue(rcr.allProjectRefs.Count == 4, "There should be four references now"); ComReferenceInfo newTlbInfo = (ComReferenceInfo)rcr.allProjectRefs[3]; Assert.IsTrue(axRefInfo.primaryOfAxImpRef == newTlbInfo, "axRefInfo should hold back reference to tlbRefInfo"); Assert.IsTrue(ComReference.AreTypeLibAttrEqual(newTlbInfo.attr, axRefInfo.attr), "The added reference should have the same attributes as the Ax reference"); Assert.IsTrue(newTlbInfo.typeLibName == axRefInfo.typeLibName, "The added reference should have the same type lib name as the Ax reference"); Assert.IsTrue(newTlbInfo.strippedTypeLibPath == axRefInfo.strippedTypeLibPath, "The added reference should have the same type lib path as the Ax reference"); Assert.IsTrue(newTlbInfo.taskItem.ItemSpec == axRefInfo.taskItem.ItemSpec, "The added reference should have the same task item spec as the Ax reference"); Assert.IsTrue(newTlbInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.wrapperTool) == ComReferenceTypes.primaryortlbimp, "The added reference should have the tlbimp/primary wrapper tool"); rcr.AddMissingTlbReferences(); Assert.IsTrue(rcr.allProjectRefs.Count == 4, "There should still be four references"); }
public void CheckIsExistingDependencyReference() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); ResolveComReference rcr = new ResolveComReference(); // populate the ResolveComReference's list of project references rcr.allDependencyRefs = new List<ComReferenceInfo>(); rcr.allDependencyRefs.Add(axRefInfo); rcr.allDependencyRefs.Add(tlbRefInfo); rcr.allDependencyRefs.Add(piaRefInfo); ComReferenceInfo referenceInfo; // find the Ax ref - should find it bool retValue = rcr.IsExistingDependencyReference(axAttr, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == axRefInfo, "ActiveX ref should be found"); // find the Tlb ref - should find it retValue = rcr.IsExistingDependencyReference(tlbAttr, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == tlbRefInfo, "Tlb ref should be found"); // find the Pia ref - should find it retValue = rcr.IsExistingDependencyReference(piaAttr, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == piaRefInfo, "Pia ref should be found"); // try to find a non existing reference - should not find it retValue = rcr.IsExistingDependencyReference(notInProjectAttr, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "not in project ref should not be found"); // Now, try to resolve a non-existent ComAssemblyReference. string path; IComReferenceResolver resolver = (IComReferenceResolver)rcr; Assert.IsFalse(resolver.ResolveComAssemblyReference("MyAssembly", out path)); Assert.AreEqual(null, path); }
public void CheckIsExistingProjectReference() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); ResolveComReference rcr = new ResolveComReference(); // populate the ResolveComReference's list of project references rcr.allProjectRefs = new List<ComReferenceInfo>(); rcr.allProjectRefs.Add(axRefInfo); rcr.allProjectRefs.Add(tlbRefInfo); rcr.allProjectRefs.Add(piaRefInfo); ComReferenceInfo referenceInfo; // find the Ax ref, matching with any type of reference - should NOT find it bool retValue = rcr.IsExistingProjectReference(axAttr, null, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "ActiveX ref should NOT be found for any type of ref"); // find the Ax ref, matching with aximp types - should find it retValue = rcr.IsExistingProjectReference(axAttr, ComReferenceTypes.aximp, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == axRefInfo, "ActiveX ref should be found for aximp ref types"); // find the Ax ref, matching with tlbimp types - should NOT find it retValue = rcr.IsExistingProjectReference(axAttr, ComReferenceTypes.tlbimp, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "ActiveX ref should NOT be found for tlbimp ref types"); // find the Tlb ref, matching with any type of reference - should find it retValue = rcr.IsExistingProjectReference(tlbAttr, null, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == tlbRefInfo, "Tlb ref should be found for any type of ref"); // find the Tlb ref, matching with tlbimp types - should find it retValue = rcr.IsExistingProjectReference(tlbAttr, ComReferenceTypes.tlbimp, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == tlbRefInfo, "Tlb ref should be found for tlbimp ref types"); // find the Tlb ref, matching with pia types - should NOT find it retValue = rcr.IsExistingProjectReference(tlbAttr, ComReferenceTypes.primary, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "Tlb ref should NOT be found for primary ref types"); // find the Pia ref, matching with any type of reference - should find it retValue = rcr.IsExistingProjectReference(piaAttr, null, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == piaRefInfo, "Pia ref should be found for any type of ref"); // find the Pia ref, matching with pia types - should find it retValue = rcr.IsExistingProjectReference(piaAttr, ComReferenceTypes.primary, out referenceInfo); Assert.IsTrue(retValue == true && referenceInfo == piaRefInfo, "Pia ref should be found for pia ref types"); // find the Pia ref, matching with pia types - should NOT find it retValue = rcr.IsExistingProjectReference(piaAttr, ComReferenceTypes.aximp, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "Pia ref should NOT be found for aximp ref types"); // try to find a non existing reference retValue = rcr.IsExistingProjectReference(notInProjectAttr, null, out referenceInfo); Assert.IsTrue(retValue == false && referenceInfo == null, "not in project ref should not be found"); }