Exemplo n.º 1
0
        // <summary>
        // Start the compilation.
        // </summary>
        // <param name="assemblyName"></param>
        // <param name="language"></param>
        // <param name="rootNamespace"></param>
        // <param name="fileList"></param>
        // <param name="isSecondPass"></param>
        // <returns></returns>
        internal bool DoCompilation(string assemblyName, string language, string rootNamespace, FileUnit[] fileList, bool isSecondPass)
        {
            bool ret = true;

            CompilationUnit compUnit = new CompilationUnit(assemblyName, language, rootNamespace, fileList);

            compUnit.Pass2 = isSecondPass;

            // Set some properties required by the CompilationUnit
            compUnit.ApplicationFile = _applicationMarkup;
            compUnit.SourcePath      = _sourceDir;

            //Set the properties required by MarkupCompiler

            _mc.SourceFileResolve += new SourceFileResolveEventHandler(OnSourceFileResolve);
            _mc.Error             += new MarkupErrorEventHandler(OnCompilerError);

            LocalizationDirectivesToLocFile localizeFlag = (LocalizationDirectivesToLocFile)_localizationDirectivesToLocFile;


            //
            // Localization file should not be generated for Intellisense build. Thus
            // checking IsRealBuild.
            //
            if ((localizeFlag == MS.Internal.LocalizationDirectivesToLocFile.All ||
                 localizeFlag == MS.Internal.LocalizationDirectivesToLocFile.CommentsOnly) &&
                (TaskFileService.IsRealBuild))
            {
                _mc.ParserHooks = new LocalizationParserHooks(_mc, localizeFlag, isSecondPass);
            }

            if (isSecondPass)
            {
                for (int i = 0; i < _mc.ReferenceAssemblyList.Count; i++)
                {
                    ReferenceAssembly asmReference = _mc.ReferenceAssemblyList[i] as ReferenceAssembly;

                    if (asmReference != null)
                    {
                        if (String.Compare(asmReference.AssemblyName, assemblyName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // Set the local assembly file to markupCompiler
                            _mc.LocalAssemblyFile = asmReference;
                        }
                    }
                }
            }

            // finally compile the app
            _mc.Compile(compUnit);

            return(ret);
        }
        //
        // Generate the necessary file lists and other information required by MarkupCompiler.
        //
        // Output ArrayLists:  localApplicationFile,
        //                     localXamlPageFileList
        //                     referenceList
        //
        private void PrepareForMarkupCompilation(out FileUnit localApplicationFile, out FileUnit[] localXamlPageFileList, out ArrayList referenceList)
        {
            Log.LogMessageFromResources(MessageImportance.Low, SRID.PreparingCompile);
            Log.LogMessageFromResources(MessageImportance.Low, SRID.OutputType, OutputType);

            // Initialize the output parameters
            localXamlPageFileList = new FileUnit[0];
            localApplicationFile = FileUnit.Empty;
            referenceList = new ArrayList();

            if (_localApplicationFile != null)
            {
                // We don't want to support multiple application definition file per project.
                localApplicationFile = new FileUnit(_localApplicationFile.FilePath, _localApplicationFile.LinkAlias, _localApplicationFile.LogicalName);

                Log.LogMessageFromResources(MessageImportance.Low, SRID.LocalRefAppDefFile, localApplicationFile);

            }

            // Generate the Xaml Markup file list
            if (_localMarkupPages != null && _localMarkupPages.Length > 0)
            {
                int localFileNum = _localMarkupPages.Length;
                localXamlPageFileList = new FileUnit[localFileNum];

                for (int i = 0; i < localFileNum; i++)
                {
                    FileUnit localPageFile = new FileUnit(_localMarkupPages[i].FilePath, _localMarkupPages[i].LinkAlias, _localMarkupPages[i].LogicalName);

                    localXamlPageFileList[i] = localPageFile;
                    Log.LogMessageFromResources(MessageImportance.Low, SRID.LocalRefMarkupPage, localPageFile);
                }
            }

            //
            // Generate the asmmebly reference list.
            // The temporay target assembly should have been added into Reference list from target file.
            //
            if (References != null && References.Length > 0)
            {
                ReferenceAssembly asmReference;
                string refpath, asmname;

                for (int i = 0; i < References.Length; i++)
                {
                    refpath = References[i].ItemSpec;
                    refpath = TaskHelper.CreateFullFilePath(refpath, SourceDir);

                    asmname = Path.GetFileNameWithoutExtension(refpath);

                    asmReference = new ReferenceAssembly(refpath, asmname);
                    referenceList.Add(asmReference);

                    //
                    // If always run the compilation in second appdomain, there is no need to specially
                    // handle the referenced assemblies.
                    // Unload the appdomain can unload all the referenced assemblies.
                    //
                    if (AlwaysCompileMarkupFilesInSeparateDomain == false)
                    {
                        bool bCouldbeChanged = TaskHelper.CouldReferenceAssemblyBeChanged(refpath, KnownReferencePaths, AssembliesGeneratedDuringBuild);

                        if (bCouldbeChanged)
                        {
                            MarkupCompiler.InitializeAssemblyState(asmname);
                        }
                    }
                }
            }

        }
Exemplo n.º 3
0
        //
        // Specially handle Reference list to prepare for xaml file compilation.
        //
        private ArrayList ProcessReferenceList( )
        {
            ArrayList referenceList = new ArrayList();

            // Generate the asmmebly reference list.
            if (References != null && References.Length > 0)
            {
                ReferenceAssembly asmReference;
                string refpath, asmname;

                for (int i = 0; i < References.Length; i++)
                {
                    // The reference path must be full file path.
                    refpath = References[i].ItemSpec;
                    refpath = TaskHelper.CreateFullFilePath(refpath, SourceDir);

                    asmname = Path.GetFileNameWithoutExtension(refpath);

                    asmReference = new ReferenceAssembly(refpath, asmname);
                    referenceList.Add(asmReference);

                    //
                    // If always run the compilation in second appdomain, there is no need to specially
                    // handle the referenced assemblies.
                    // Unload the appdomain can unload all the referenced assemblies.
                    //
                    if (AlwaysCompileMarkupFilesInSeparateDomain == false)
                    {
                        bool bCouldbeChanged = TaskHelper.CouldReferenceAssemblyBeChanged(refpath, KnownReferencePaths, AssembliesGeneratedDuringBuild);

                        if (bCouldbeChanged)
                        {
                            MarkupCompiler.InitializeAssemblyState(asmname);
                        }
                    }

                    Log.LogMessageFromResources(MessageImportance.Low, SRID.ReferenceFile, refpath);

                }
            }

            return referenceList;
        }