Exemple #1
0
        public Assembly Generate(IAssemblySource assemblySource, string outputAssemblyPath, IEnumerable <ManifestResource> manifestResources = null)
        {
            // Parameter manifestResources is obsolete parameter for legacy plugins.
            // If provided, Rhetos CLI build command will not consider generated source as a part of the application's source,
            // instead it will fall back to legacy behavior (DeployPackages) and will generate source and DLL files as assets files.
            bool isLegecayResourcesLibrary = manifestResources != null;

            manifestResources = manifestResources ?? Array.Empty <ManifestResource>();

            // Save source file and it's hash value:
            string sourceCode = // The compiler parameters are included in the source, in order to invalidate the assembly cache when the parameters are changed.
                                string.Concat(assemblySource.RegisteredReferences.Select(reference => $"// Reference: {PathAndVersion(reference)}\r\n"))
                                + string.Concat(manifestResources.Select(resource => $"// Resource: \"{resource.Name}\", {PathAndVersion(resource.Path)}\r\n"))
                                + $"// Debug = \"{_buildOptions.Debug}\"\r\n\r\n"
                                + assemblySource.GeneratedCode;

            if (string.IsNullOrEmpty(_buildEnvironment.GeneratedSourceFolder) || isLegecayResourcesLibrary)
            {
                string sourcePath = Path.GetFullPath(Path.ChangeExtension(outputAssemblyPath, ".cs"));
                File.WriteAllText(sourcePath, sourceCode, Encoding.UTF8);
                return(CompileAssemblyOrGetFromCache(outputAssemblyPath, sourceCode, sourcePath, assemblySource.RegisteredReferences, manifestResources));
            }
            else
            {
                _sourceWriter.Add(Path.GetFileNameWithoutExtension(outputAssemblyPath) + ".cs", sourceCode);
                return(null);
            }
        }
        public void Generate()
        {
            var sourceFiles = _codeGenerator.ExecutePluginsToFiles(_pluginRepository, "/*", "*/", _initialDomCodeGenerator);

            foreach (var sourceFile in sourceFiles)
            {
                _sourceWriter.Add(sourceFile.Key + ".cs", sourceFile.Value);
            }
        }
Exemple #3
0
        public void Generate()
        {
            var sourceFiles = _codeGenerator.ExecutePluginsToFiles(_pluginRepository, "/*", "*/", null);

            if (!string.IsNullOrEmpty(_buildEnvironment.GeneratedSourceFolder))
            {
                foreach (var sourceFile in sourceFiles)
                {
                    _sourceWriter.Add(sourceFile.Key + ".cs", sourceFile.Value.GeneratedCode);
                }
            }
            else
            {
                var targetAssemblies = sourceFiles
                                       .GroupBy(sourceFile => sourceFile.Key.Split('\\').First())
                                       .Select(sourceFileGroup => new
                {
                    Name           = sourceFileGroup.Key,
                    AssemblySource = new AssemblySource
                    {
                        GeneratedCode        = string.Join("\r\n", sourceFileGroup.OrderBy(sourceFile => sourceFile.Key).Select(sourceFile => sourceFile.Value.GeneratedCode)),
                        RegisteredReferences = sourceFileGroup.SelectMany(sourceFile => sourceFile.Value.RegisteredReferences).Distinct().OrderBy(name => name)
                    },
                    AssemblyFile = Paths.GetDomAssemblyFile((DomAssemblies)Enum.Parse(typeof(DomAssemblies), sourceFileGroup.Key)),
                })
                                       .ToList();

                Graph.SortByGivenOrder(targetAssemblies,
                                       new string[] { DomAssemblies.Model.ToString(), DomAssemblies.Orm.ToString(), DomAssemblies.Repositories.ToString() },
                                       targetAssembly => targetAssembly.Name);
                AddReferences(targetAssemblies[1].AssemblySource, new[] { targetAssemblies[0].AssemblyFile });
                AddReferences(targetAssemblies[2].AssemblySource, new[] { targetAssemblies[0].AssemblyFile, targetAssemblies[1].AssemblyFile });

                foreach (var targetAssembly in targetAssemblies)
                {
                    _assemblyGenerator.Generate(targetAssembly.AssemblySource, targetAssembly.AssemblyFile);
                }
            }
        }