//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ #region Public Methods /// <summary> /// Execute method in Task /// </summary> /// <returns></returns> public override bool Execute() { TaskHelper.DisplayLogo(Log, nameof(MarkupCompilePass2)); // // Create the TaskFileService instance here // _taskFileService = new TaskFileService(this) as ITaskFileService; try { IsSupportedOutputType(OutputType); Log.LogMessageFromResources(MessageImportance.Low, SRID.CurrentDirectory, SourceDir); // If wrong files are set to some properties, the task // should stop here immediatelly. if (_nErrors > 0) { Log.LogErrorWithCodeFromResources(SRID.WrongPropertySetting); } else { bool hasLocalXamlFiles; hasLocalXamlFiles = InitLocalXamlCache(); if (!hasLocalXamlFiles) { // There is no valid input xaml files. // No need to do further work. // stop here. return(true); } // create output directory if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } // Call the Markup Compiler to do the real compiling work ArrayList referenceList; FileUnit localApplicationFile; FileUnit[] localXamlPageFileList; // Prepare the appropriate file lists required by MarkupCompiler. PrepareForMarkupCompilation(out localApplicationFile, out localXamlPageFileList, out referenceList); // Do the real Pass2 compilation work here. DoLocalReferenceMarkupCompilation(localApplicationFile, localXamlPageFileList, referenceList); // Generate the required output items. GenerateOutputItems(); Log.LogMessageFromResources(MessageImportance.Low, SRID.CompilationDone); } } #pragma warning disable 6500 catch (Exception e) { string message; string errorId; errorId = Log.ExtractMessageCode(e.Message, out message); if (String.IsNullOrEmpty(errorId)) { errorId = UnknownErrorID; message = SR.Get(SRID.UnknownBuildError, message); } Log.LogError(null, errorId, null, null, 0, 0, 0, 0, message, null); _nErrors++; } catch // Non-CLS compliant errors { Log.LogErrorWithCodeFromResources(SRID.NonClsError); _nErrors++; } #pragma warning restore 6500 if (_nErrors > 0) { // When error counter is changed, the appropriate error message should have // been reported. // // The task should cleanup all the cache files so that all the xaml files will // get chance to recompile next time. // string stateFileName = OutputPath + AssemblyName + (TaskFileService.IsRealBuild? SharedStrings.StateFile : SharedStrings.IntellisenseStateFile); string localTypeCacheFileName = OutputPath + AssemblyName + (TaskFileService.IsRealBuild? SharedStrings.LocalTypeCacheFile : SharedStrings.IntellisenseLocalTypeCacheFile); if (TaskFileService.Exists(stateFileName)) { TaskFileService.Delete(stateFileName); } if (TaskFileService.Exists(localTypeCacheFileName)) { TaskFileService.Delete(localTypeCacheFileName); } return(false); } else { // Mark Pass2 as completed in the cache string stateFileName = OutputPath + AssemblyName + (TaskFileService.IsRealBuild ? SharedStrings.StateFile : SharedStrings.IntellisenseStateFile); if (TaskFileService.Exists(stateFileName)) { CompilerState compilerState = new CompilerState(stateFileName, TaskFileService); compilerState.LoadStateInformation(); if (compilerState.Pass2Required) { compilerState.Pass2Required = false; compilerState.SaveStateInformation(); } } Log.LogMessageFromResources(SRID.CompileSucceed_Pass2); return(true); } }