From 2da056e2dea7e98413afc0552c40466358def759 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 29 Jan 2020 00:57:50 +0200 Subject: Implemented Roslyn experiment. --- .../RoslynTest/ConsoleApp8/ConsoleApp8.sln | 25 +++ .../RoslynTest/ConsoleApp8/ConsoleApp8/App.config | 50 ++++++ .../ConsoleApp8/ConsoleApp8/ConsoleApp8.csproj | 182 +++++++++++++++++++++ .../RoslynTest/ConsoleApp8/ConsoleApp8/Program.cs | 64 ++++++++ .../ConsoleApp8/Properties/AssemblyInfo.cs | 36 ++++ .../RoslynTest/ConsoleApp8/ConsoleApp8/lib.csx | 14 ++ .../RoslynTest/ConsoleApp8/ConsoleApp8/main.csx | 16 ++ .../ConsoleApp8/ConsoleApp8/packages.config | 52 ++++++ 8 files changed, 439 insertions(+) create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8.sln create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/App.config create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/ConsoleApp8.csproj create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Program.cs create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Properties/AssemblyInfo.cs create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib.csx create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main.csx create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/packages.config (limited to 'Software/Experiments') diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8.sln b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8.sln new file mode 100644 index 000000000..16b91c118 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2042 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp8", "ConsoleApp8\ConsoleApp8.csproj", "{01E63EB6-C3D8-4C61-9208-724E3CB23277}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {01E63EB6-C3D8-4C61-9208-724E3CB23277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01E63EB6-C3D8-4C61-9208-724E3CB23277}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01E63EB6-C3D8-4C61-9208-724E3CB23277}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01E63EB6-C3D8-4C61-9208-724E3CB23277}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FF8F8769-CC77-4AE4-AC2C-8BC259BE09AC} + EndGlobalSection +EndGlobal diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/App.config b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/App.config new file mode 100644 index 000000000..9830299e4 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/App.config @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/ConsoleApp8.csproj b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/ConsoleApp8.csproj new file mode 100644 index 000000000..8e816cf94 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/ConsoleApp8.csproj @@ -0,0 +1,182 @@ + + + + + + Debug + AnyCPU + {01E63EB6-C3D8-4C61-9208-724E3CB23277} + Exe + ConsoleApp8 + ConsoleApp8 + v4.6.1 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeAnalysis.Common.2.10.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.2.10.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.10.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll + + + ..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.10.0\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll + + + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll + + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + True + True + + + + ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + True + True + + + ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll + True + True + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + True + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + True + True + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + True + True + + + + ..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + True + + + ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + True + True + + + ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + True + True + + + + + + + + + + ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + True + True + + + ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + True + True + + + ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll + True + True + + + ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + True + True + + + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Program.cs b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Program.cs new file mode 100644 index 000000000..5067058c8 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Program.cs @@ -0,0 +1,64 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace ConsoleApp8 +{ + public class TestResult + { + public String Value { get; set; } + } + + public class Program + { + public class Globals + { + public String GlobalMessage { get; set; } + } + + static void Main(string[] args) + { + + var scriptOptions = ScriptOptions.Default. + WithFilePath(System.Windows.Forms.Application.StartupPath). + WithReferences(new Assembly[] { typeof(System.Windows.Forms.Form).Assembly, typeof(Program).Assembly }); + + + + String script = File.ReadAllText("main.csx"); + + + var s = CSharpScript.Create(script, scriptOptions); + var compileResult = s.Compile(); + + if (compileResult.Count() > 0) + { + var error = compileResult.First(); + + String erroFile = error.Location.SourceTree.FilePath; + var errorMessage = error.GetMessage(); + var severity = error.Severity; + var line = error.Location.GetMappedLineSpan(); + int lineNumber = line.StartLinePosition.Line + 1; + int colNumber = line.StartLinePosition.Character + 1; + int length = line.EndLinePosition.Character - line.StartLinePosition.Character; + } + + var globals = new Globals() { GlobalMessage = "Hi from lib" }; + + var result = CSharpScript.RunAsync(script + Environment.NewLine + Environment.NewLine + "return OnExecute(GlobalMessage);", scriptOptions, globals: globals).Result; + + Console.ReadLine(); + + } + } +} diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Properties/AssemblyInfo.cs b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..690a7ce18 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApp8")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApp8")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("01e63eb6-c3d8-4c61-9208-724e3cb23277")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib.csx b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib.csx new file mode 100644 index 000000000..93c79d32f --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib.csx @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +public class lib +{ + public void Show(String msg) + { + MessageBox.Show(msg); + } +} diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main.csx b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main.csx new file mode 100644 index 000000000..f0b973033 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main.csx @@ -0,0 +1,16 @@ +#load "C:\Users\Roy\source\repos\ConsoleApp8\ConsoleApp8\bin\Debug\lib.csx" + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConsoleApp8; + +public TestResult OnExecute(String msg) +{ + lib l = new lib(); + l.Show(msg); + + return new TestResult() { Value = "This is a return value" }; +} diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/packages.config b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/packages.config new file mode 100644 index 000000000..6fceca3c1 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/packages.config @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.3.1