Exemplo n.º 1
0
        public void GenerateSource()
        {
            var t = new ResolveComReference.AxImp();

            Assert.IsFalse(t.GenerateSource, "GenerateSource should be false by default");
            CommandLine.ValidateNoParameterStartsWith(t, @"/source", false /* no response file */);

            t.GenerateSource = true;
            Assert.IsTrue(t.GenerateSource, "GenerateSource should be true");
            CommandLine.ValidateHasParameter(t, @"/source", false /* no response file */);
        }
Exemplo n.º 2
0
        public void NoLogo()
        {
            var t = new ResolveComReference.AxImp();

            Assert.IsFalse(t.NoLogo, "NoLogo should be false by default");
            CommandLine.ValidateNoParameterStartsWith(t, @"/nologo", false /* no response file */);

            t.NoLogo = true;
            Assert.IsTrue(t.NoLogo, "NoLogo should be true");
            CommandLine.ValidateHasParameter(t, @"/nologo", false /* no response file */);
        }
Exemplo n.º 3
0
        public void ActiveXControlName()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = "AxInterop.Foo.dll";

            Assert.Null(t.ActiveXControlName); // "ActiveXControlName should be null by default"

            t.ActiveXControlName = testParameterValue;
            Assert.Equal(testParameterValue, t.ActiveXControlName); // "New ActiveXControlName value should be set"
            CommandLine.ValidateHasParameter(t, testParameterValue, false /* no response file */);
        }
Exemplo n.º 4
0
        public void ActiveXControlNameWithSpaces()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = @"c:\Program Files\AxInterop.Foo.dll";

            Assert.IsNull(t.ActiveXControlName, "ActiveXControlName should be null by default");

            t.ActiveXControlName = testParameterValue;
            Assert.AreEqual(testParameterValue, t.ActiveXControlName, "New ActiveXControlName value should be set");
            CommandLine.ValidateHasParameter(t, testParameterValue, false /* no response file */);
        }
Exemplo n.º 5
0
        public void DelaySign()
        {
            AxTlbBaseTask t = new ResolveComReference.AxImp();

            Assert.False(t.DelaySign); // "DelaySign should be false by default"
            CommandLine.ValidateNoParameterStartsWith(t, @"/delaysign", false /* no response file */);

            t.DelaySign = true;
            Assert.True(t.DelaySign); // "DelaySign should be true"
            CommandLine.ValidateHasParameter(t, @"/delaysign", false /* no response file */);
        }
Exemplo n.º 6
0
        /*
         * 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);
        }
Exemplo n.º 7
0
        /*
         * 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;
        }
        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);
        }
Exemplo n.º 9
0
        public void OutputAssembly()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = "AxInterop.Foo.dll";

            Assert.IsNull(t.OutputAssembly, "OutputAssembly should be null by default");
            CommandLine.ValidateNoParameterStartsWith(t, @"/out:", false /* no response file */);

            t.OutputAssembly = testParameterValue;
            Assert.AreEqual(testParameterValue, t.OutputAssembly, "New OutputAssembly value should be set");
            CommandLine.ValidateHasParameter(t, @"/out:" + testParameterValue, false /* no response file */);
        }
Exemplo n.º 10
0
        public void TaskFailsWithNoInputs()
        {
            var t = new ResolveComReference.AxImp();

            Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxImp.NoInputFileSpecified");
        }
Exemplo n.º 11
0
        public void Silent()
        {
            var t = new ResolveComReference.AxImp();

            Assert.IsFalse(t.Silent, "Silent should be false by default");
            CommandLine.ValidateNoParameterStartsWith(t, @"/silent", false /* no response file */);

            t.Silent = true;
            Assert.IsTrue(t.Silent, "Silent should be true");
            CommandLine.ValidateHasParameter(t, @"/silent", false /* no response file */);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public void Verbose()
        {
            var t = new ResolveComReference.AxImp();

            Assert.False(t.Verbose); // "Verbose should be false by default"
            CommandLine.ValidateNoParameterStartsWith(t, @"/verbose", false /* no response file */);

            t.Verbose = true;
            Assert.True(t.Verbose); // "Verbose should be true"
            CommandLine.ValidateHasParameter(t, @"/verbose", false /* no response file */);
        }
Exemplo n.º 14
0
        public void RuntimeCallableWrapper()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = "Interop.Foo.dll";

            Assert.Null(t.RuntimeCallableWrapperAssembly); // "RuntimeCallableWrapper should be null by default"
            CommandLine.ValidateNoParameterStartsWith(t, @"/rcw:", false /* no response file */);

            t.RuntimeCallableWrapperAssembly = testParameterValue;
            Assert.Equal(testParameterValue, t.RuntimeCallableWrapperAssembly); // "New RuntimeCallableWrapper value should be set"
            CommandLine.ValidateHasParameter(t, @"/rcw:" + testParameterValue, false /* no response file */);
        }
Exemplo n.º 15
0
        public void OutputAssemblyWithSpaces()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = @"c:\Program Files\AxInterop.Foo.dll";

            Assert.Null(t.OutputAssembly); // "OutputAssembly should be null by default"
            CommandLine.ValidateNoParameterStartsWith(t, @"/out:", false /* no response file */);

            t.OutputAssembly = testParameterValue;
            Assert.Equal(testParameterValue, t.OutputAssembly); // "New OutputAssembly value should be set"
            CommandLine.ValidateHasParameter(t, @"/out:" + testParameterValue, false /* no response file */);
        }
Exemplo n.º 16
0
        public void KeyContainerWithSpaces()
        {
            AxTlbBaseTask t = new ResolveComReference.AxImp();
            string testParameterValue = @"my Key Container";

            Assert.Null(t.KeyContainer); // "KeyContainer should be null by default"
            CommandLine.ValidateNoParameterStartsWith(t, @"/keycontainer:", false /* no response file */);

            t.KeyContainer = testParameterValue;
            Assert.Equal(testParameterValue, t.KeyContainer); // "New KeyContainer value should be set"
            CommandLine.ValidateHasParameter(t, @"/keycontainer:" + testParameterValue, false /* no response file */);
        }
Exemplo n.º 17
0
        public void RuntimeCallableWrapperWithSpaces()
        {
            var t = new ResolveComReference.AxImp();
            string testParameterValue = @"C:\Program Files\Microsoft Visual Studio 10.0\Interop.Foo.dll";

            Assert.IsNull(t.RuntimeCallableWrapperAssembly, "RuntimeCallableWrapper should be null by default");
            CommandLine.ValidateNoParameterStartsWith(t, @"/rcw:", false /* no response file */);

            t.RuntimeCallableWrapperAssembly = testParameterValue;
            Assert.AreEqual(testParameterValue, t.RuntimeCallableWrapperAssembly, "New RuntimeCallableWrapper value should be set");
            CommandLine.ValidateHasParameter(t, @"/rcw:" + testParameterValue, false /* no response file */);
        }
Exemplo n.º 18
0
        public void KeyFile()
        {
            var t = new ResolveComReference.AxImp();
            t.ActiveXControlName = "FakeControl.ocx";
            string badParameterValue = "myKeyFile.key";
            string goodParameterValue = null;

            try
            {
                goodParameterValue = FileUtilities.GetTemporaryFile();
                t.ToolPath = Path.GetTempPath();

                Assert.Null(t.KeyFile); // "KeyFile should be null by default"
                CommandLine.ValidateNoParameterStartsWith(t, @"/keyfile:", false /* no response file */);

                t.KeyFile = badParameterValue;
                Assert.Equal(badParameterValue, t.KeyFile); // "New KeyFile value should be set"
                CommandLine.ValidateHasParameter(t, @"/keyfile:" + badParameterValue, false /* no response file */);
                Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxTlbBaseTask.InvalidKeyFileSpecified", t.KeyFile);

                t.KeyFile = goodParameterValue;
                Assert.Equal(goodParameterValue, t.KeyFile); // "New KeyFile value should be set"
                CommandLine.ValidateHasParameter(t, @"/keyfile:" + goodParameterValue, false /* no response file */);
                Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxTlbBaseTask.StrongNameUtils.NoKeyPairInFile", t.KeyFile);
            }
            finally
            {
                if (goodParameterValue != null)
                {
                    // get rid of the generated temp file
                    File.Delete(goodParameterValue);
                }
            }
        }