diff --git a/bootstrap/prebuild.dll b/bootstrap/prebuild.dll index 53eaf34..2efe2f7 100644 Binary files a/bootstrap/prebuild.dll and b/bootstrap/prebuild.dll differ diff --git a/compile.bat b/compile.bat index f7dafff..4c154bd 100644 --- a/compile.bat +++ b/compile.bat @@ -1,4 +1,4 @@ @echo off -runprebuild.bat +call runprebuild.bat dotnet build -c Release \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index 15cf0f9..bda8613 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -104,8 +104,11 @@ + + + diff --git a/source/Prebuild/Core/Nodes/TextGenNode.cs b/source/Prebuild/Core/Nodes/TextGenNode.cs index d32090b..b61f9d8 100644 --- a/source/Prebuild/Core/Nodes/TextGenNode.cs +++ b/source/Prebuild/Core/Nodes/TextGenNode.cs @@ -17,6 +17,7 @@ namespace Prebuild.Core.Nodes private string m_Generator; private bool m_AutoGen = true; private string m_OutputName; + private List m_Libs = new(); #endregion @@ -24,9 +25,17 @@ namespace Prebuild.Core.Nodes public override void Parse(XmlNode node) { m_Name = Helper.AttributeValue(node, "name", ""); - m_Generator = Helper.AttributeValue(node, "generator", "TextTemplatingFileGenerator"); - m_AutoGen = Helper.ParseBoolean(node, "autogen", true); m_OutputName = Helper.AttributeValue(node, "output", ""); + + foreach (XmlNode childNode in node.ChildNodes) + { + var data = Kernel.Instance.ParseNode(childNode, this); + if(data is ReferenceNode) + { + m_Libs.Add(((ReferenceNode)data).Name); + } + } + } #endregion @@ -71,6 +80,14 @@ namespace Prebuild.Core.Nodes } } + public string Libraries + { + get + { + return String.Join("..", m_Libs); + } + } + #endregion } } diff --git a/source/Prebuild/Core/Targets/VSGenericTarget.cs b/source/Prebuild/Core/Targets/VSGenericTarget.cs index 4683a5a..323ac79 100644 --- a/source/Prebuild/Core/Targets/VSGenericTarget.cs +++ b/source/Prebuild/Core/Targets/VSGenericTarget.cs @@ -696,7 +696,7 @@ public abstract class VSGenericTarget : ITarget string outputFile = Path.Combine(project.Path, node.OutputName); ps.WriteLine(" "); - ps.WriteLine($" "); + ps.WriteLine($" "); ps.WriteLine($" "); } } diff --git a/source/SnapWrap/SnapWrap.cs b/source/SnapWrap/SnapWrap.cs index dcf352f..bb578b0 100644 --- a/source/SnapWrap/SnapWrap.cs +++ b/source/SnapWrap/SnapWrap.cs @@ -1,11 +1,8 @@ -using Microsoft.CodeAnalysis.CSharp.Scripting; -using Microsoft.CodeAnalysis.Scripting; -using System; -using System.Collections.Generic; +using System; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; +using System.Diagnostics; namespace SnapWrap { @@ -15,26 +12,31 @@ namespace SnapWrap { string input = args[0]; string output = args[1]; + var customImports = args[2].Split(".."); try { var inputCode = File.ReadAllText(input); - var options = ScriptOptions.Default - .WithReferences(AppDomain.CurrentDomain.GetAssemblies()) // Add necessary assemblies - .WithImports("System"); + .WithReferences(AppDomain.CurrentDomain.GetAssemblies()) // Add necessary assemblies + .WithImports(customImports) + .WithAllowUnsafe(true); - using (var sw = new StreamWriter(output)) + + // Capture console output using custom class + using (var consoleOutput = new ConsoleOutput()) { - Console.SetOut(sw); // Redirect console output var scriptState = CSharpScript.RunAsync(inputCode, options).Result; - // Reset console output - Console.SetOut(new StreamWriter(Console.OpenStandardOutput())); + // Get captured output from the ConsoleOutput class + string capturedOutput = consoleOutput.GetOutput(); + + // Write captured output to output file + File.WriteAllText(output, capturedOutput); - Console.WriteLine("Output file generated successfully."); } + Console.WriteLine("Output file generated successfully."); } catch (Exception ex) { @@ -42,4 +44,32 @@ namespace SnapWrap } } } + + // Custom class to capture console output + public class ConsoleOutput : IDisposable + { + private StringWriter _stringWriter; + private TextWriter _originalOutput; + + public ConsoleOutput() + { + _stringWriter = new StringWriter(); + _originalOutput = Console.Out; + Console.SetOut(_stringWriter); + } + + public string GetOutput() + { + Console.SetOut(_originalOutput); + string capturedOutput = _stringWriter.ToString(); + _stringWriter.Dispose(); + return capturedOutput; + } + + public void Dispose() + { + Console.SetOut(_originalOutput); + _stringWriter.Dispose(); + } + } } diff --git a/source/SnapWrap/SnapWrap.csproj b/source/SnapWrap/SnapWrap.csproj index 4349f9a..5a36060 100644 --- a/source/SnapWrap/SnapWrap.csproj +++ b/source/SnapWrap/SnapWrap.csproj @@ -61,8 +61,10 @@ AnyCPU + +