/* * Method: GenerateWrapper * * Generates a wrapper for this reference. */ internal bool GenerateWrapper(out ComReferenceWrapperInfo wrapperInfo) { wrapperInfo = null; // The tool gets the public key for itself, but we get it here anyway to // give nice messages in errors cases. StrongNameKeyPair keyPair = null; byte[] publicKey = null; GetAndValidateStrongNameKey(out keyPair, out publicKey); bool generateWrapperSucceeded = true; string tlbName = ReferenceInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName); // Generate wrapper out-of-proc using aximp.exe from the target framework. MUST // HAVE SET SDKTOOLSPATH TO THE TARGET SDK TO WORK var axImp = new ResolveComReference.AxImp(); if (ReferenceInfo != null) { axImp.ActiveXControlName = ReferenceInfo.strippedTypeLibPath; } axImp.BuildEngine = BuildEngine; axImp.ToolPath = ToolPath; axImp.EnvironmentVariables = EnvironmentVariables; axImp.DelaySign = DelaySign; axImp.GenerateSource = false; axImp.KeyContainer = KeyContainer; axImp.KeyFile = KeyFile; axImp.Silent = Silent; if (ReferenceInfo != null && ReferenceInfo.primaryOfAxImpRef != null && ReferenceInfo.primaryOfAxImpRef.resolvedWrapper != null && ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path != null) { // This path should hit unless there was a prior resolution error or bug in the resolution code. // The reason is that everything (tlbs and pias) gets resolved before AxImp references. axImp.RuntimeCallableWrapperAssembly = ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path; } axImp.OutputAssembly = Path.Combine(OutputDirectory, GetWrapperFileName()); generateWrapperSucceeded = axImp.Execute(); string wrapperPath = GetWrapperPath(); // store the wrapper info... wrapperInfo = new ComReferenceWrapperInfo(); wrapperInfo.path = wrapperPath; wrapperInfo.assembly = Assembly.UnsafeLoadFrom(wrapperInfo.path); // ...and we're done! return(generateWrapperSucceeded); }
internal bool GenerateWrapper(out ComReferenceWrapperInfo wrapperInfo) { wrapperInfo = null; StrongNameKeyPair keyPair = null; byte[] publicKey = null; StrongNameUtils.GetStrongNameKey(base.Log, base.KeyFile, base.KeyContainer, out keyPair, out publicKey); if (!base.DelaySign && (keyPair == null)) { if ((base.KeyContainer != null) && (base.KeyContainer.Length > 0)) { base.Log.LogErrorWithCodeFromResources(null, this.ReferenceInfo.SourceItemSpec, 0, 0, 0, 0, "ResolveComReference.StrongNameUtils.NoKeyPairInContainer", new object[] { base.KeyContainer }); throw new StrongNameException(); } if ((base.KeyFile != null) && (base.KeyFile.Length > 0)) { base.Log.LogErrorWithCodeFromResources(null, this.ReferenceInfo.SourceItemSpec, 0, 0, 0, 0, "ResolveComReference.StrongNameUtils.NoKeyPairInFile", new object[] { base.KeyFile }); throw new StrongNameException(); } } bool flag = true; this.ReferenceInfo.taskItem.GetMetadata("TlbReferenceName"); ResolveComReference.AxImp imp = new ResolveComReference.AxImp { ActiveXControlName = this.ReferenceInfo.typeLibPath, BuildEngine = base.BuildEngine, ToolPath = base.ToolPath, EnvironmentVariables = base.EnvironmentVariables, DelaySign = base.DelaySign, GenerateSource = false, KeyContainer = base.KeyContainer, KeyFile = base.KeyFile }; if (((this.ReferenceInfo != null) && (this.ReferenceInfo.primaryOfAxImpRef != null)) && ((this.ReferenceInfo.primaryOfAxImpRef.resolvedWrapper != null) && (this.ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path != null))) { imp.RuntimeCallableWrapperAssembly = this.ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path; } imp.OutputAssembly = Path.Combine(this.OutputDirectory, base.GetWrapperFileName()); flag = imp.Execute(); string wrapperPath = base.GetWrapperPath(); wrapperInfo = new ComReferenceWrapperInfo(); wrapperInfo.path = wrapperPath; wrapperInfo.assembly = Assembly.UnsafeLoadFrom(wrapperInfo.path); return(flag); }
/* * Method: GenerateWrapper * * Generates a wrapper for this reference. */ internal bool GenerateWrapper(out ComReferenceWrapperInfo wrapperInfo) { wrapperInfo = null; // The tool gets the public key for itself, but we get it here anyway to // give nice messages in errors cases. StrongNameKeyPair keyPair = null; byte[] publicKey = null; GetAndValidateStrongNameKey(out keyPair, out publicKey); bool generateWrapperSucceeded = true; string tlbName = ReferenceInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName); // Generate wrapper out-of-proc using aximp.exe from the target framework. MUST // HAVE SET SDKTOOLSPATH TO THE TARGET SDK TO WORK var axImp = new ResolveComReference.AxImp(); axImp.ActiveXControlName = ReferenceInfo.strippedTypeLibPath; axImp.BuildEngine = BuildEngine; axImp.ToolPath = ToolPath; axImp.EnvironmentVariables = EnvironmentVariables; axImp.DelaySign = DelaySign; axImp.GenerateSource = false; axImp.KeyContainer = KeyContainer; axImp.KeyFile = KeyFile; axImp.Silent = Silent; if (ReferenceInfo != null && ReferenceInfo.primaryOfAxImpRef != null && ReferenceInfo.primaryOfAxImpRef.resolvedWrapper != null && ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path != null) { // This path should hit unless there was a prior resolution error or bug in the resolution code. // The reason is that everything (tlbs and pias) gets resolved before AxImp references. axImp.RuntimeCallableWrapperAssembly = ReferenceInfo.primaryOfAxImpRef.resolvedWrapper.path; } axImp.OutputAssembly = Path.Combine(OutputDirectory, GetWrapperFileName()); generateWrapperSucceeded = axImp.Execute(); string wrapperPath = GetWrapperPath(); // store the wrapper info... wrapperInfo = new ComReferenceWrapperInfo(); wrapperInfo.path = wrapperPath; wrapperInfo.assembly = Assembly.UnsafeLoadFrom(wrapperInfo.path); // ...and we're done! return generateWrapperSucceeded; }
public void ToolPath() { var t = new ResolveComReference.AxImp(); t.ActiveXControlName = "FakeControl.ocx"; string badParameterValue = @"C:\Program Files\Microsoft Visual Studio 10.0\My Fake SDK Path"; string goodParameterValue = Path.GetTempPath(); bool taskPassed; Assert.Null(t.ToolPath); // "ToolPath should be null by default" Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxTlbBaseTask.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath); t.ToolPath = badParameterValue; Assert.Equal(badParameterValue, t.ToolPath); // "New ToolPath value should be set" Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxTlbBaseTask.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath); MockEngine e = new MockEngine(); t.BuildEngine = e; t.ToolPath = goodParameterValue; Assert.Equal(goodParameterValue, t.ToolPath); // "New ToolPath value should be set" taskPassed = t.Execute(); Assert.False(taskPassed); // "Task should still fail -- there are other things wrong with it." // but that particular error shouldn't be there anymore. string toolPathMessage = t.Log.FormatResourceString("AxTlbBaseTask.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath); string messageWithNoCode; string toolPathCode = t.Log.ExtractMessageCode(toolPathMessage, out messageWithNoCode); e.AssertLogDoesntContain(toolPathCode); }