diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-02-06 07:51:27 +0100 |
|---|---|---|
| committer | j-p <jp_bruyere@hotmail.com> | 2020-05-10 00:50:02 +0200 |
| commit | a58f28741bf91be4d0fc077a6088bd8864e12c1f (patch) | |
| tree | 2c522ce056c6c34722ec8c78cc2b009709f3ab45 /Samples | |
| parent | c4e776610e3e8d37b608ebd2b40690d5dd4e3bbd (diff) | |
update with msbuild
Diffstat (limited to 'Samples')
19 files changed, 636 insertions, 2 deletions
diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs index 1360b652..059bf852 100644 --- a/Samples/BasicTests/BasicTests.cs +++ b/Samples/BasicTests/BasicTests.cs @@ -29,8 +29,9 @@ namespace tests // += KeyboardKeyDown1; //testFiles = new string [] { @"Interfaces/Experimental/testDock.crow" }; - testFiles = new string [] { @"Interfaces/Divers/welcome.crow" }; - //testFiles = new string [] { @"Interfaces/Divers/testSlider.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" }; + testFiles = new string [] { @"Interfaces/Group/5.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/perfMeasures.crow" }; //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" }; testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray (); testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray (); diff --git a/Samples/BasicTests/BasicTests.csproj b/Samples/BasicTests/BasicTests.csproj index b231b253..e1208a42 100644 --- a/Samples/BasicTests/BasicTests.csproj +++ b/Samples/BasicTests/BasicTests.csproj @@ -25,5 +25,9 @@ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Link>Interfaces\%(RecursiveDir)%(Filename)%(Extension)</Link> </None> + <EmbeddedResource Include="..\common\ui\templates\**\*.*"> + <LogicalName>ui.%(Filename)%(Extension)</LogicalName> + <Link>Templates\%(Filename)%(Extension)</Link> + </EmbeddedResource> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Samples/common/ui/Interfaces/Group/5.crow b/Samples/common/ui/Interfaces/Group/5.crow new file mode 100644 index 00000000..b344bc6c --- /dev/null +++ b/Samples/common/ui/Interfaces/Group/5.crow @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<VerticalStack Background="DimGrey" Margin="10" Fit="true" MinimumSize="200,20"> + <Label Font="droid bold,20" Text="Label1" Margin="5" Width="Stretched" Height="Fit" Background="Jet"/> + <Label Font="droid bold,20" Text="Label1" Margin="5" Width="Stretched" Height="Fit" Background="Jet"/> + <Label Font="droid bold,20" Text="Label1" Margin="5" Width="Stretched" Height="Fit" Background="Jet"/> + <Label Font="droid bold,20" Text="Label1" Margin="5" Width="Stretched" Height="Fit" Background="Jet"/> +</VerticalStack>
\ No newline at end of file diff --git a/Samples/common/ui/templates/CheckBox2.imlt b/Samples/common/ui/templates/CheckBox2.imlt new file mode 100644 index 00000000..c2bfe8da --- /dev/null +++ b/Samples/common/ui/templates/CheckBox2.imlt @@ -0,0 +1,7 @@ +<Label Font="{./Font}" Text="{./Caption}" Height="{./HeightPolicy}" Width="{./WidthPolicy}" + Margin="3" + Background="{./Background}" + Foreground="DimGrey" + TextAlignment="Center" + MouseEnter="{Foreground=White}" + MouseLeave="{Foreground=DimGrey}"/>
\ No newline at end of file diff --git a/Samples/common/ui/templates/TabItem.template b/Samples/common/ui/templates/TabItem.template new file mode 100644 index 00000000..fd0f310d --- /dev/null +++ b/Samples/common/ui/templates/TabItem.template @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<GenericStack Orientation="Vertical" Spacing="0" + Background="{./Background}" + MouseEnter="{/caption.Foreground=White}" + MouseLeave="{/caption.Foreground=Grey}"> + <HorizontalStack Left="{./TabOffset}" + Name="TabTitle" + HorizontalAlignment="Left" + Height="{./TabHeight}" + Width="{./TabWidth}"> + <Label Name="caption" Text="{./Caption}" Foreground="Grey" Width="Stretched"/> + <Label Text="{./ViewIndex}" Foreground="Green"/> + <Label Text="{./TabOffset}" Foreground="Red"/> + <Border CornerRadius="5" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> + <Image Focusable="true" Name="Image" Margin="0" Width="Stretched" Height="Stretched" Path="#Crow.Icons.exit2.svg" + MouseClick="./butCloseTabClick"/> + </Border> + </HorizontalStack> + <Container Margin="20"> + <Container Background="DimGrey" Name="Content"/> + </Container> +</GenericStack> + diff --git a/Samples/common/ui/templates/TmpExpandable.goml b/Samples/common/ui/templates/TmpExpandable.goml new file mode 100644 index 00000000..9dddcebb --- /dev/null +++ b/Samples/common/ui/templates/TmpExpandable.goml @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<!--<VerticalStack Height="{../HeightPolicy}" Width="{../WidthPolicy}" MouseClick="../onMouseClick"> + <Label Text="{../../Caption}" Width="{../../WidthPolicy}"/> + <Container Name="Content" Visible="false" Height="{../../HeightPolicy}" Width="{../../WidthPolicy}"/> +</VerticalStack>--> +<Group BorderWidth="1" Foreground="LightGray" + MouseClick="../onMouseClick"> + <VerticalStack> + <Label Text="{../../../Caption}"/> + <Container Name="Content" Visible="false"/> + </VerticalStack> +</Group>
\ No newline at end of file diff --git a/Samples/common/ui/templates/colorItem.crow b/Samples/common/ui/templates/colorItem.crow new file mode 100644 index 00000000..30bfe3d3 --- /dev/null +++ b/Samples/common/ui/templates/colorItem.crow @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Border Foreground="Transparent" Focusable="true" HorizontalAlignment="Left" Height="Fit" Width="200"> + <HorizontalStack Margin="0" + MouseEnter="{Background=hgradient|0:DarkRed|1:Transparent}" + MouseLeave="{Background=Transparent}"> + <Widget Height="12" Width="20" Background="{}" Margin="0" CornerRadius="3"/> + <Label Text="{}" Margin="0" Width="Stretched"/> + </HorizontalStack> +</Border> + diff --git a/Samples/common/ui/templates/colorItem2.crow b/Samples/common/ui/templates/colorItem2.crow new file mode 100644 index 00000000..83239b32 --- /dev/null +++ b/Samples/common/ui/templates/colorItem2.crow @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Border Foreground="Transparent" Focusable="true" HorizontalAlignment="Left" Height="Fit"> + <HorizontalStack Margin="0" + MouseEnter="{Background=CornflowerBlue}" + MouseLeave="{Background=Transparent}"> + <Widget Height="8" Width="14" Background="{}" Margin="0" CornerRadius="2"/> + <Label Text="{}" Margin="0" Width="Stretched" Font="mono, 8"/> + </HorizontalStack> +</Border> + diff --git a/Samples/common/ui/templates/itemTmp.goml b/Samples/common/ui/templates/itemTmp.goml new file mode 100644 index 00000000..fadf5e63 --- /dev/null +++ b/Samples/common/ui/templates/itemTmp.goml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<Border BorderWidth="3"> + <Label Text="{Name}" Focusable="true" Width="Stretched" Height="Fit" Margin="0" + MouseEnter="{Background=Red}" + MouseLeave="{Background=Transparent}" + /> +</Border> + diff --git a/Samples/common/ui/templates/log.xml b/Samples/common/ui/templates/log.xml new file mode 100644 index 00000000..1039f7be --- /dev/null +++ b/Samples/common/ui/templates/log.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<Container Name="topContainer" HorizontalAlignment="Center" VerticalAlignment="Top" + Margin="2" + Width="600" Height="-1"> + <Border Margin="2" BorderWidth="1" Background="0,6;0,6;0,6;0,6" Height="-1"> + <Group Width="0" Name="logs"> + <VerticalStack Name="VerticalStack" Width="0" Focusable="False"> + <Label Name="line1" Width="0" Text="Line1" Margin="0"/> + <Label Name="line2" Width="0" Text="Line2" Margin="0"/> + <Label Name="line3" Width="0" Text="Line3" Margin="0"/> + <Label Name="line4" Width="0" Text="Line4" Margin="0"/> + </VerticalStack> + <Button Name="btOk" Background="Gray" Fit="True" + HorizontalAlignment="Right" VerticalAlignment="Bottom" + MouseClick="BtOk_MouseClick"> + <Label Text="Ok" Margin="3" Foreground="White" /> + </Button> + </Group> + </Border> +</Container> + diff --git a/Samples/common/ui/templates/perfMsr.crow b/Samples/common/ui/templates/perfMsr.crow new file mode 100644 index 00000000..06f7ae3c --- /dev/null +++ b/Samples/common/ui/templates/perfMsr.crow @@ -0,0 +1,38 @@ +<?xml version="1.0"?> + + <VerticalStack Spacing="1" Height="Fit" Width="Stretched"> + <HorizontalStack Background="DarkSlateGrey"> + <Label Text="{Name}" Width="Stretched" Font="doid bold, 10" Margin="2"/> + <Button Caption="Reset" MouseClick="onResetClick" Height="Fit"/> + </HorizontalStack> + <HorizontalStack Height="Fit" Width="Fit" HorizontalAlignment="Left"> + <HorizontalStack Style="HStackMeasure"> + <Label Text="Cur:" Style="FpsLabel"/> + <Label Text="{current}" Style="FpsDisp"/> + </HorizontalStack> + <HorizontalStack Style="HStackMeasure"> + <Label Text="Min:" Style="FpsLabel"/> + <Label Text="{minimum}" Style="FpsDisp"/> + </HorizontalStack> + <HorizontalStack Style="HStackMeasure"> + <Label Text="Mean:" Style="FpsLabel"/> + <Label Text="{mean}" Style="FpsDisp"/> + </HorizontalStack> + <HorizontalStack Style="HStackMeasure"> + <Label Text="Max:" Style="FpsLabel"/> + <Label Text="{maximum}" Style="FpsDisp"/> + </HorizontalStack> + </HorizontalStack> + <Border Foreground="White" Width="Stretched" Height="60"> + <Trend Background="Black" NewValue="{current}" Minimum="{minimum}" Maximum="{maximum}"/> + </Border> +<!-- <HorizontalStack> + <Label Text="Total:" Style="FpsLabel"/> + <Label Text="{total}" Style="FpsDisp"/> + </HorizontalStack> + <HorizontalStack> + <Label Text="Cpt:" Style="FpsLabel"/> + <Label Text="{cptMeasures}" Style="FpsDisp"/> + </HorizontalStack>--> + </VerticalStack> + diff --git a/Samples/common/ui/templates/test.style b/Samples/common/ui/templates/test.style new file mode 100644 index 00000000..6f5dc8fb --- /dev/null +++ b/Samples/common/ui/templates/test.style @@ -0,0 +1,49 @@ +FpsLabel { + Width = "30"; + Font = "droid, 10"; + Margin = "0"; + TextAlignment = "Center"; +} +FpsDisp { + Font = "droid bold, 10"; + Width = "60"; + Margin = "0"; + CornerRadius = "3"; + TextAlignment = "Center"; + Background = "MediumSeaGreen"; +} +HStackMeasure { + Margin = "2"; + Width = "Fit"; + Height = "Fit"; + Background = "DimGrey"; +} +CheckBox2 { + Template= "Interfaces/CheckBox2.imlt"; + Background = "Jet"; + Checked="{Background=MediumSeaGreen}"; + Unchecked = "{Background=Jet}"; +} +RadioButton2 { + Template="Interfaces/CheckBox2.imlt"; + Background = "Jet"; + Checked = "{Background=MediumSeaGreen}"; + Unchecked = "{Background=Jet}"; +} +labPerf { + Font = "droid, 8"; + Width = "50%"; +} +labPerfVal{ + Font = "droid, 8"; + Width = "50%"; +} +DbgLogViewer{ + Background = "Onyx"; + Font = "mono, 8"; + Foreground = "LightGrey"; + Focusable = "true"; +} +DockWindow{ + Background = "0.1,0.1,0.1,0.5"; +} diff --git a/Samples/common/ui/templates/testMeter.goml b/Samples/common/ui/templates/testMeter.goml new file mode 100644 index 00000000..2c840a8e --- /dev/null +++ b/Samples/common/ui/templates/testMeter.goml @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<AnalogMeter Width="Fit" Height="Fit" Background="White" Foreground="Black" Value="{fps}" Minimum="Stretched" Maximum="100"/>
\ No newline at end of file diff --git a/Samples/common/ui/templates/testWindow.goml.sav b/Samples/common/ui/templates/testWindow.goml.sav new file mode 100644 index 00000000..42b4b744 --- /dev/null +++ b/Samples/common/ui/templates/testWindow.goml.sav @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!--<Group>--> +<Window Name="window1" Left="10" Top="10" Title="Test window" + Width="250" Height="300" > + <VerticalStack Name="contentVSStack" Margin="10" Spacing="10"> + <Slider Name="slider" Height="10" Width="0"/> + + <HorizontalStack Width="0" Height="-1" Margin="10" Background="BlueCrayola"> + <Checkbox Height="-1" Width="80"/> + <GraphicObject Width="0"/> + <Checkbox Height="-1" Width="80"/> + </HorizontalStack> + <Groupbox Text="test" Height="-1" Width="-1" Margin="5"> + <VerticalStack Height="-1" Width="0" > + <RadioButton Caption="Radio 1" Background="Red" /> + <RadioButton Caption="Radio 2" IsChecked="true" /> + <RadioButton Caption="Radio 3" /> + </VerticalStack> + </Groupbox> +<!-- <Checkbox Height="-1" Width="-1" Background="Red" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Right"/>--> + </VerticalStack> +</Window> +<!--</Group>--> +<!-- <Label Text="{fps}" Background="DarkRed"/> + <Label Text="{fpsMin}" /> + <Label Text="{fpsMax}" />-->
\ No newline at end of file diff --git a/Samples/common/ui/templates/tmpDirItem.goml b/Samples/common/ui/templates/tmpDirItem.goml new file mode 100644 index 00000000..41665d13 --- /dev/null +++ b/Samples/common/ui/templates/tmpDirItem.goml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> + <HorizontalStack Width="Fit" Height="Fit" Focusable="true" + HorizontalAlignment="Left" + MouseEnter="{Background=RoyalBlue}" + MouseLeave="{Background=Transparent}"> + <Image Width="16" Height="16" Path="#Tests.image.folder1.svg" SvgSub="{Attributes}"/> + <Label Text="{Name}" Width="Fit" Height="Fit" Margin="0"/> + <Label Text="{Attributes}" Width="Fit" Height="Fit" Margin="0"/> + <Label Text="{Extension}" Width="Fit" Height="Fit" Margin="0"/> + </HorizontalStack> + diff --git a/Samples/common/ui/templates/tmpMembers.goml b/Samples/common/ui/templates/tmpMembers.goml new file mode 100644 index 00000000..f48d8d68 --- /dev/null +++ b/Samples/common/ui/templates/tmpMembers.goml @@ -0,0 +1,9 @@ +<?xml version="1.0"?> + <HorizontalStack Width="Stretched" Height="Fit" Focusable="true" + MouseEnter="{Background=SkyBlue}" + MouseLeave="{Background=Transparent}"> + <Image Width="8" Height="8" Path="#Crow.Images.Icons.member.svg" SvgSub="{GetIcon}"/> + <Label Text="{Name}" Width="Stretched" Height="Fit" Margin="1"/> + <Label Text="{MemberType}" Width="Fit" Height="Fit" Margin="0"/> + </HorizontalStack> + diff --git a/Samples/common/ui/templates/treeList.crow b/Samples/common/ui/templates/treeList.crow new file mode 100644 index 00000000..ca59c17f --- /dev/null +++ b/Samples/common/ui/templates/treeList.crow @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<VerticalStack Height="Fit" Name="List"/>
\ No newline at end of file diff --git a/Samples/testMSBuild/Program.cs b/Samples/testMSBuild/Program.cs new file mode 100644 index 00000000..87814739 --- /dev/null +++ b/Samples/testMSBuild/Program.cs @@ -0,0 +1,370 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; +using Microsoft.Build.Framework; + +namespace testMSBuild +{ + class Program + { + + //const string msbuildRoot = "/usr/lib/mono/msbuild/Current/bin/"; + const string msbuildRoot = "/usr/share/dotnet/sdk/3.1.101/"; + //const string msbuildRoot = "/mnt/data/src/microsoft/msbuild/artifacts/bin/bootstrap/netcoreapp2.1/MSBuild/"; + const string toolsVersion = "Current"; + + static void Main (string [] args) + { + /*var nativeSharedMethod = typeof (SolutionFile).Assembly.GetType ("Microsoft.Build.Shared.NativeMethodsShared"); + var isMonoField = nativeSharedMethod.GetField ("_isMono", BindingFlags.Static | BindingFlags.NonPublic); + isMonoField.SetValue (null, true);*/ + + //Environment.SetEnvironmentVariable (MSBUILD_EXE_PATH, "/usr/share/dotnet/sdk/3.1.101/MSBuild.dll"); + Environment.SetEnvironmentVariable ("MSBUILD_EXE_PATH", Path.Combine(msbuildRoot, "MSBuild.dll")); + Environment.SetEnvironmentVariable ("MSBUILD_NUGET_PATH", "/home/jp/.nuget/packages"); + + + //Environment.SetEnvironmentVariable ("COREHOST_TRACE", "1"); + + AppDomain currentDomain = AppDomain.CurrentDomain; + currentDomain.AssemblyResolve += msbuildAssembliesResolve; + + compile (); + } + + static Assembly msbuildAssembliesResolve (object sender, ResolveEventArgs args) + { + string assemblyPath = Path.Combine (msbuildRoot, new AssemblyName (args.Name).Name + ".dll"); + /*Console.BackgroundColor = ConsoleColor.DarkBlue; + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine ($"Probing: {assemblyPath}"); + Console.ResetColor ();*/ + if (!File.Exists (assemblyPath)) return null; + Assembly assembly = Assembly.LoadFrom (assemblyPath); + return assembly; + } + + + static void compile () + { + //Console.WriteLine ($"{Microsoft.Build. BuildEnvironmentHelper.Instance.CurrentMSBuildExePath}"); + string slnPath = "/mnt/devel/glfw-sharp/glfw-sharp.sln";//<--- change here can be another VS type ex: .vcxproj + //string slnPath = "/mnt/devel/vke.net/vke.net.sln";//<--- change here can be another VS type ex: .vcxproj + //string csprojPath = "/mnt/devel/glfw-sharp/glfw-sharp.csproj"; + //ILogger Logger = new BasicLogger (); + ILogger Logger = new Microsoft.Build.Logging.ConsoleLogger (); + Logger.Verbosity = LoggerVerbosity.Minimal; + //Logger.Parameters = "V=DIAG;consoleloggerparameters:ShowEventId"; + ProjectCollection projectCollection = new ProjectCollection (); + projectCollection.DefaultToolsVersion = toolsVersion; + //projectCollection.IsBuildEnabled = false; + //projectCollection.LoadProject (projectFileName); + SolutionFile sln = SolutionFile.Parse (slnPath); + + /*foreach (ProjectInSolution pis in sln.ProjectsInOrder) { + Console.WriteLine ($"{pis.ProjectName} {pis.RelativePath} {pis.ProjectType}"); + }*/ + + + //Project project = new Project (projectCollection); + BuildParameters buildParams = new BuildParameters (projectCollection); + buildParams.Loggers = new List<ILogger> () { Logger }; + //buildParams.DefaultToolsVersion = "Current"; + //buildParams.DetailedSummary = true; + //buildParams.LogInitialPropertiesAndItems = true; + //buildParams.LogTaskInputs = true; + + buildParams.ResetCaches = false; + + Dictionary<String, String> globalProperties = new Dictionary<String, String> (); + + globalProperties ["Configuration"] = sln.GetDefaultConfigurationName (); + globalProperties ["Platform"] = sln.GetDefaultPlatformName (); + + + //globalProperties ["RollForward"] = "none"; + //globalProperties ["_IsRollForwardSupported"] = "false"; + + //globalProperties ["GenerateRuntimeConfigurationFiles"] = "true"; + + //globalProperties ["NuGetPackageRoot"] = "/home/jp/.nuget/packages"; + //globalProperties ["RoslynTargetsPath"] = Path.Combine (msbuildRoot, "Roslyn/"); + //globalProperties ["MSBuildSDKsPath"] = Path.Combine (msbuildRoot, "Sdks/"); + + //globalProperties ["AdditionalLibPaths"] = msbuildRoot; + //globalProperties ["AssemblySearchPaths"] = msbuildRoot; + + + //globalProperty.Add ("CSharpCoreTargetsPath", "/usr/share/dotnet/sdk/3.1.101/Roslyn/Microsoft.CSharp.Core.targets"); + + /*ProjectInstance pinst = new ProjectInstance (csprojPath, globalProperties, "Current"); + if (pinst.Build (new String [] { "Build" }, buildParams.Loggers, out System.Collections.Generic.IDictionary<string, Microsoft.Build.Execution.TargetResult> targetOutputs)) + Console.WriteLine ("Success"); + ProjectRootElement pre = pinst.ToProjectRootElement ();*/ + + //List <Project> projects = new List<Project> (); + + //projectCollection.ProjectAdded += (sender, e) => { + // // pc = sender as ProjectCollection; + // // Console.ForegroundColor = ConsoleColor.Yellow; + // // Console.WriteLine ($"Proj added: {e.ProjectRootElement} {e.ProjectRootElement.FullPath}"); + // // Console.ResetColor (); + + // Project p = new Project (e.ProjectRootElement);//, globalProperties, toolsVersion, projectCollection); + // // //projects.Add (p); + // Console.WriteLine ($"\nEvaluated properties:"); + // foreach (var pi in p.Properties) + // Console.WriteLine ($"\t{pi.Name} = {pi.EvaluatedValue}"); + // Console.WriteLine (""); + + // // //foreach (ProjectItem pi in p.AllEvaluatedItems) + // // //Console.WriteLine ($"{pi.ItemType} {pi.EvaluatedInclude}"); + // // /*foreach (GlobResult gr in p.GetAllGlobs()) { + // // foreach (string g in gr.IncludeGlobs) { + // // Console.WriteLine ($"\t\t{g}"); + // // } + //}; + + //}; + + BuildManager.DefaultBuildManager.ResetCaches (); + + //string[] targetsToBuild = { "ResolveAssemblyReferences" }; + string [] targetsToBuild = { "restore", "build"}; + //string [] targetsToBuild = { "Rebuild" }; + + //globalProperties ["Configuration"] = "ReleaseSpirVTasks"; + + BuildRequestData buildRequest = new BuildRequestData (slnPath, globalProperties, "Current", targetsToBuild, null); + + BuildResult buildResult = BuildManager.DefaultBuildManager.Build (buildParams, buildRequest); + + + if (buildResult.OverallResult == BuildResultCode.Success) { + Console.WriteLine ("Build succes."); + } else { + foreach (var item in buildResult.ResultsByTarget) { + Console.WriteLine ($"{item.Key} -> {item.Value.ResultCode} {item.Value.ToString()}"); + } + + Console.WriteLine ("Error: " + buildResult.Exception); + } + //Console.WriteLine ($"proj count: {}"); + //MessageBox.Show (Logger.GetLogString ()); + /*foreach (Project p in buildParams. ..LoadedProjects) { + foreach (ProjectItem pi in p.AllEvaluatedItems) { + Console.WriteLine ($"{pi.ItemType} {pi}"); + } + }*/ + + } + } + + public class FileLogger : ILogger + { + public LoggerVerbosity Verbosity { get => throw new NotImplementedException (); set => throw new NotImplementedException (); } + public string Parameters { get => throw new NotImplementedException (); set => throw new NotImplementedException (); } + + Stream log; + StreamWriter sw; + + public void Initialize (IEventSource eventSource) + { + log = new FileStream ("buildlog.txt", FileMode.Create); + sw = new StreamWriter (log); + + eventSource.MessageRaised += (sender, e) => sw.WriteLine ($"{e.Message}"); + eventSource.BuildStarted += (sender, e) => sw.WriteLine("Build started"); + eventSource.BuildFinished += (sender, e) => sw.WriteLine ("Build finished"); + } + + public void Shutdown () + { + log.Flush (); + sw.Dispose (); + log.Dispose (); + } + } + + public class BasicLogger : ILogger + { + public LoggerVerbosity Verbosity { get; set; } + public string Parameters { get; set; } + + public void Initialize (IEventSource eventSource) + { + //eventSource.ProjectStarted += (sender, e) => Console.WriteLine ($"Building project: {e.Message}"); + //eventSource.ProjectFinished += (sender, e) => Console.WriteLine ($"Done project: {e.Message}"); + eventSource.ErrorRaised += (sender, e) => { + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Red; + Console.WriteLine ($"{e.Message}"); + Console.ResetColor (); + }; + eventSource.TargetStarted += (sender, e) => { + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine ($"Target start: {e.TargetName}<-{e.ParentTarget} {e.Message}"); + Console.ResetColor (); + }; + eventSource.TargetFinished += (sender, e) => { + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine ($"\tDone {e.TargetName} ({e.Succeeded}) : {e.Message}"); + Console.ResetColor (); + }; + + eventSource.MessageRaised += (sender, e) => { + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine ($"{e.HelpKeyword} {e.Message}"); + Console.ResetColor (); + }; + //eventSource.AnyEventRaised += (sender, e) => Console.WriteLine ($"{e.Timestamp}:{e.SenderName}=>{e.Message}"); + //eventSource.BuildStarted += (sender, e) => Console.WriteLine("Build started"); + eventSource.BuildFinished += (sender, e) => Console.WriteLine ("Build finished"); + } + + public void Shutdown () + { + } + } + + //public class BasicLogger : ILogger + // { + // MemoryStream streamMem = new MemoryStream (); + // /// <summary> + // /// Initialize is guaranteed to be called by MSBuild at the start of the build + // /// before any events are raised. + // /// </summary> + // public override void Initialize (IEventSource eventSource) + // { + + // try { + // // Open the file + // this.streamWriter = new StreamWriter (streamMem); + // //this.streamWriter = new StreamWriter(logFile); + // } catch (Exception ex) { + // if + // ( + // ex is UnauthorizedAccessException + // || ex is ArgumentNullException + // || ex is PathTooLongException + // || ex is DirectoryNotFoundException + // || ex is NotSupportedException + // || ex is ArgumentException + // || ex is SecurityException + // || ex is IOException + // ) { + // throw new LoggerException ("Failed to create log file: " + ex.Message); + // } else { + // // Unexpected failure + // throw; + // } + // } + + // // For brevity, we'll only register for certain event types. Loggers can also + // // register to handle TargetStarted/Finished and other events. + // eventSource.ProjectStarted += new ProjectStartedEventHandler (eventSource_ProjectStarted); + // eventSource.TaskStarted += new TaskStartedEventHandler (eventSource_TaskStarted); + // eventSource.MessageRaised += new BuildMessageEventHandler (eventSource_MessageRaised); + // eventSource.WarningRaised += new BuildWarningEventHandler (eventSource_WarningRaised); + // eventSource.ErrorRaised += new BuildErrorEventHandler (eventSource_ErrorRaised); + // eventSource.ProjectFinished += new ProjectFinishedEventHandler (eventSource_ProjectFinished); + // } + + // void eventSource_ErrorRaised (object sender, BuildErrorEventArgs e) + // { + // // BuildErrorEventArgs adds LineNumber, ColumnNumber, File, amongst other parameters + // string line = String.Format (": ERROR {0}({1},{2}): ", e.File, e.LineNumber, e.ColumnNumber); + // WriteLineWithSenderAndMessage (line, e); + // } + + // void eventSource_WarningRaised (object sender, BuildWarningEventArgs e) + // { + // // BuildWarningEventArgs adds LineNumber, ColumnNumber, File, amongst other parameters + // string line = String.Format (": Warning {0}({1},{2}): ", e.File, e.LineNumber, e.ColumnNumber); + // WriteLineWithSenderAndMessage (line, e); + // } + + // void eventSource_MessageRaised (object sender, BuildMessageEventArgs e) + // { + // // BuildMessageEventArgs adds Importance to BuildEventArgs + // // Let's take account of the verbosity setting we've been passed in deciding whether to log the message + // if ((e.Importance == MessageImportance.High && IsVerbosityAtLeast (LoggerVerbosity.Minimal)) + // || (e.Importance == MessageImportance.Normal && IsVerbosityAtLeast (LoggerVerbosity.Normal)) + // || (e.Importance == MessageImportance.Low && IsVerbosityAtLeast (LoggerVerbosity.Detailed)) + // ) { + // WriteLineWithSenderAndMessage (String.Empty, e); + // } + // } + + // void eventSource_TaskStarted (object sender, TaskStartedEventArgs e) + // { + // // TaskStartedEventArgs adds ProjectFile, TaskFile, TaskName + // // To keep this log clean, this logger will ignore these events. + // } + + // void eventSource_ProjectStarted (object sender, ProjectStartedEventArgs e) + // { + // // ProjectStartedEventArgs adds ProjectFile, TargetNames + // // Just the regular message string is good enough here, so just display that. + // WriteLine (String.Empty, e); + // indent++; + // } + + // void eventSource_ProjectFinished (object sender, ProjectFinishedEventArgs e) + // { + // // The regular message string is good enough here too. + // indent--; + // WriteLine (String.Empty, e); + // } + + // /// <summary> + // /// Write a line to the log, adding the SenderName and Message + // /// (these parameters are on all MSBuild event argument objects) + // /// </summary> + // private void WriteLineWithSenderAndMessage (string line, BuildEventArgs e) + // { + // if (0 == String.Compare (e.SenderName, "MSBuild", true /*ignore case*/)) { + // // Well, if the sender name is MSBuild, let's leave it out for prettiness + // WriteLine (line, e); + // } else { + // WriteLine (e.SenderName + ": " + line, e); + // } + // } + + // /// <summary> + // /// Just write a line to the log + // /// </summary> + // private void WriteLine (string line, BuildEventArgs e) + // { + // for (int i = indent; i > 0; i--) { + // streamWriter.Write ("\t"); + // } + // streamWriter.WriteLine (line + e.Message); + // } + + + // public string GetLogString () + // { + // var sr = new StreamReader (streamMem); + // var myStr = sr.ReadToEnd (); + // return myStr; + // } + // /// <summary> + // /// Shutdown() is guaranteed to be called by MSBuild at the end of the build, after all + // /// events have been raised. + // /// </summary> + // /// + // /// + // public override void Shutdown () + // { + // streamWriter.Flush (); + // streamMem.Position = 0; + // } + // private StreamWriter streamWriter; + // private int indent; + //} +} diff --git a/Samples/testMSBuild/testMSBuild.csproj b/Samples/testMSBuild/testMSBuild.csproj new file mode 100644 index 00000000..9eff9e78 --- /dev/null +++ b/Samples/testMSBuild/testMSBuild.csproj @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <!-- <TargetFramework>net472</TargetFramework>--> + <TargetFramework>netcoreapp3.1</TargetFramework> + <ReleaseVersion>0.8.0</ReleaseVersion> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="Microsoft.Build" Version="16.*"> + <IncludeAssets>compile</IncludeAssets> + </PackageReference> + <PackageReference Include="Microsoft.Build.Framework" Version="16.*"> + <IncludeAssets>compile</IncludeAssets> + </PackageReference> + <PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.*"> + <IncludeAssets>compile</IncludeAssets> + </PackageReference> + <PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.*"> + <IncludeAssets>compile</IncludeAssets> + </PackageReference> + </ItemGroup> +</Project>
\ No newline at end of file |