Click here to Skip to main content
15,885,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi all,

I started to use the Roslyn compiler as a service.
I need to use it in my application.

First I download the package from NuGet Library.
Then built the code.
However, I am a beginner in it and there is an error in the code.

Could any one explain to me how to use Roslyn to that purpose.

This is the code.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;

namespace RoslynTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ScriptEngine engine = new ScriptEngine();
            Session session = Session.Create();
            session.AddReference("System.Core");
            engine.Execute("using system;", session);
            engine.Execute("for(int i=0;i<10; i++) console.writeLine(i*1); ", session);

        }
    }
}
Thanks in advance.
Posted
Updated 3-Feb-14 22:36pm
v2
Comments
Richard MacCutchan 4-Feb-14 4:51am    
Where and what is the error?
Y.Mohammed 5-Feb-14 2:35am    
I think it is in the library of the program

This are the errors:
Error 1 'Roslyn.Scripting.Session' does not contain a definition for 'Create'
Error 2 'Roslyn.Scripting.CSharp.ScriptEngine' does not contain a definition for 'Execute' and no extension method 'Execute' accepting a first argument of type 'Roslyn.Scripting.CSharp.ScriptEngine' could be found (are you missing a using directive or an assembly reference?)

1 solution

I found the way of writing the code..
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;

namespace RoslynTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var engine = new ScriptEngine();
            var session = engine.CreateSession();

            string text = System.IO.File.ReadAllText(@"C:\test.txt");
            session.Execute(text);


        }
    }
}


Thanx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900