Ejemplo n.º 1
0
        public void Test1()
        {
            var content = @"using System;
namespace Test.Dummy
{
  public class TestClass
  {
    
  }
}";
            var txt     = File.ReadAllText(@"C:\Users\prbhosal\Desktop\projectcontext.json");

            var context = JsonConvert.DeserializeObject <CommonProjectContext>(txt);

            var manager = WorkspaceManager.Create(context);

            manager.AddDocumentToProject(
                context.ProjectFullPath,
                Path.Combine(Path.GetDirectoryName(context.ProjectFullPath), "Test.cs"),
                content);


            var compilation = manager.GetCompilationAsync().Result;

            if (compilation.Assembly != null)
            {
            }
        }
        private void AddFrameworkServices(ComponentRegistry componentRegistry, IProjectContext projectInformation)
        {
            //Ordering of services is important here

            var applicationInfo = new ApplicationInfo(
                projectInformation.ProjectName,
                Path.GetDirectoryName(projectInformation.ProjectFullPath));

            componentRegistry.RegisterComponent <IProjectContext>(projectInformation);

            _codeGenerationContext = new CodeGenerationContext(_codeGenArguments, projectInformation.ProjectFullPath);
            componentRegistry.RegisterComponent <CodeGenerationContext>(_codeGenerationContext);

            componentRegistry.RegisterComponent <IApplicationInfo>(applicationInfo);
            componentRegistry.RegisterComponent <ICodeGenAssemblyLoadContext>(new DefaultAssemblyLoadContext());
            componentRegistry.RegisterComponent <WorkspaceManager>(WorkspaceManager.Create(projectInformation));

            componentRegistry.RegisterComponent <IFileSystem>(DefaultFileSystem.Instance);
            componentRegistry.RegisterComponent <ILogger>(_logger);

            componentRegistry.RegisterComponentWithDependencies <ICodeGenerationAssemblyProvider, CodeGenerationAssemblyProvider>();
            componentRegistry.RegisterComponentWithDependencies <ITemplateLocator, TemplateLocator>();

            componentRegistry.RegisterComponentWithDependencies <CodeGenCommand, CodeGenCommand>();
        }