internal bool SaveStateInformation(MarkupCompilePass1 mcPass1) { Debug.Assert(String.IsNullOrEmpty(_stateFilePath) != true, "StateFilePath must not be empty."); Debug.Assert(mcPass1 != null, "A valid instance of MarkupCompilePass1 must be passed to method SaveCacheInformation."); Debug.Assert(_cacheInfoList.Length == (int)CompilerStateType.MaxCount, "The Cache string array should be already allocated."); // Transfer the cache related information from mcPass1 to this instance. AssemblyName = mcPass1.AssemblyName; AssemblyVersion = mcPass1.AssemblyVersion; AssemblyPublicKeyToken = mcPass1.AssemblyPublicKeyToken; OutputType = mcPass1.OutputType; Language = mcPass1.Language; LanguageSourceExtension = mcPass1.LanguageSourceExtension; OutputPath = mcPass1.OutputPath; RootNamespace = mcPass1.RootNamespace; LocalizationDirectivesToLocFile = mcPass1.LocalizationDirectivesToLocFile; HostInBrowser = mcPass1.HostInBrowser; DefineConstants = mcPass1.DefineConstants; ApplicationFile = mcPass1.ApplicationFile; PageMarkup = mcPass1.PageMarkupCache; ContentFiles = mcPass1.ContentFilesCache; SourceCodeFiles = mcPass1.SourceCodeFilesCache; References = mcPass1.ReferencesCache; PageMarkupFileNames = GenerateStringFromFileNames(mcPass1.PageMarkup); SplashImage = mcPass1.SplashImageName; Pass2Required = (mcPass1.RequirePass2ForMainAssembly || mcPass1.RequirePass2ForSatelliteAssembly); return(SaveStateInformation()); }
private static void Compile(string assemblyName, string rootNamespace, string outputPath, string targetPath, List <string> references, List <string> markup, List <string> sources) { var referenceItems = references.Select(r => new TaskItem(r) as ITaskItem) .ToArray(); var markupItems = markup.Select(r => new TaskItem(r) as ITaskItem).ToArray(); var buildEngine = new Engine(); var sourceFileItems = sources.Select(src => new TaskItem(src) as ITaskItem).ToArray(); var markupCompilePass1 = new MarkupCompilePass1 { BuildEngine = buildEngine, Language = "C#", SourceCodeFiles = sourceFileItems, //ApplicationMarkup = new ITaskItem[] { // new TaskItem(@"c:\Users\Mihhail\AppData\Local\Temp\csharp-wpf-test-project\App.xaml"), //}, PageMarkup = markupItems, AssemblyName = assemblyName, LanguageSourceExtension = ".cs", AlwaysCompileMarkupFilesInSeparateDomain = true, XamlDebuggingInformation = true, OutputPath = outputPath, OutputType = "Exe", HostInBrowser = "false", RootNamespace = rootNamespace, References = referenceItems }; var result = markupCompilePass1.Execute(); // var temporaryAssembly = Path.Combine(outputPath, assemblyName + ".exe"); var temporaryAssembly = targetPath; var markupCompilePass2 = new MarkupCompilePass2 { BuildEngine = buildEngine, AssemblyName = assemblyName, OutputType = "Exe", Language = "C#", LocalizationDirectivesToLocFile = "", RootNamespace = rootNamespace, References = referenceItems.Concat(new[] { new TaskItem(temporaryAssembly) }) .ToArray(), AlwaysCompileMarkupFilesInSeparateDomain = true, XamlDebuggingInformation = true, OutputPath = outputPath, }; markupCompilePass2.BuildEngine = markupCompilePass1.BuildEngine; result = markupCompilePass2.Execute(); Console.WriteLine("Pass 1 generated"); foreach (var generatedBamlFile in markupCompilePass1.GeneratedBamlFiles) { Console.WriteLine("_o|" + generatedBamlFile.ItemSpec); } Console.WriteLine("Pass 2 generated"); foreach (var generatedBamlFile in markupCompilePass2.GeneratedBaml) { Console.WriteLine("_o|" + generatedBamlFile.ItemSpec); } }
// // Save the local reference related information from MarkupCompilePass1 task to cache file. // internal bool SaveCacheInformation(MarkupCompilePass1 mcPass1) { Debug.Assert(String.IsNullOrEmpty(_localCacheFile) != true, "_localCacheFile must not be empty."); Debug.Assert(mcPass1 != null, "A valid instance of MarkupCompilePass1 must be passed to method SaveCacheInformation."); bool bSuccess = false; // Transfer the cache related information from mcPass1 to this instance. LocalApplicationFile = mcPass1.LocalApplicationFile; LocalMarkupPages = mcPass1.LocalMarkupPages; // Save the cache information to the cache file. MemoryStream memStream = new MemoryStream(); // using Disposes the StreamWriter when it ends. Disposing the StreamWriter // also closes the underlying MemoryStream. Furthermore, don't add BOM here // since TaskFileService.WriteFile adds it. using (StreamWriter sw = new StreamWriter(memStream, new UTF8Encoding(false))) { // Write InternalTypeHelperFile only when Pass1 asks Pass2 to do further check. if (mcPass1.FurtherCheckInternalTypeHelper) { sw.WriteLine(mcPass1.InternalTypeHelperFile); } else { sw.WriteLine(String.Empty); } // Write the ApplicationFile for Pass2 compilation. if (LocalApplicationFile == null) { sw.WriteLine(String.Empty); } else { sw.WriteLine(LocalApplicationFile.Serialize()); } if (LocalMarkupPages != null && LocalMarkupPages.Length > 0) { for (int i = 0; i < LocalMarkupPages.Length; i++) { sw.WriteLine(LocalMarkupPages[i].Serialize( )); } } sw.Flush(); _taskFileService.WriteFile(memStream.ToArray(), _localCacheFile); bSuccess = true; } return(bSuccess); }
// <summary> // ctor of IncrementalCompileAnalyzer // </summary> internal IncrementalCompileAnalyzer(MarkupCompilePass1 mcPass1) { _mcPass1 = mcPass1; _analyzeResult = RecompileCategory.NoRecompile; }