Esempio n. 1
0
        internal string CompileVisualBasicSource()
        {
            List <ITaskItem> sources = new List <ITaskItem>();

            sources.Add(new TaskItem(this.GeneratedCodeFile));

            // If client has added extra user code into the
            // compile request, add it in now
            string userCodeFile = this.UserCodeFile;

            if (!string.IsNullOrEmpty(userCodeFile))
            {
                sources.Add(new TaskItem(userCodeFile));
            }

            // Transform references into a list of ITaskItems.
            // Here, we skip over mscorlib explicitly because this is already included as a project reference.
            List <ITaskItem> references =
                this.ReferenceAssemblies
                .Where(reference => !reference.EndsWith("mscorlib.dll", StringComparison.Ordinal))
                .Select <string, ITaskItem>(reference => new TaskItem(reference) as ITaskItem)
                .ToList();

            Vbc             vbc         = new Vbc();
            MockBuildEngine buildEngine = this.MockBuildEngine;

            vbc.BuildEngine = buildEngine; // needed before task can log

            vbc.NoStandardLib    = true;   // don't include std lib stuff -- we're feeding it silverlight
            vbc.NoConfig         = true;   // don't load the vbc.rsp file to get references
            vbc.TargetType       = "library";
            vbc.Sources          = sources.ToArray();
            vbc.References       = references.ToArray();
            vbc.SdkPath          = CompilerHelper.GetSilverlightSdkReferenceAssembliesPath();
            vbc.RootNamespace    = "TestRootNS";
            vbc.DefineConstants += "SILVERLIGHT";

            vbc.OutputAssembly = new TaskItem(this.OutputAssemblyName);

            bool result = false;

            try
            {
                result = vbc.Execute();
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception occurred invoking VBC task on " + sources[0].ItemSpec + ":\r\n" + ex);
            }

            Assert.IsTrue(result, "VBC failed to compile " + sources[0].ItemSpec + ":\r\n" + buildEngine.ConsoleLogger.Errors);
            return(vbc.OutputAssembly.ItemSpec);
        }