Inheritance: AssemblySourceFileGeneratorBase
Ejemplo n.º 1
0
        static void CreateAssembly(PackageInfo package, string outputPath = null)
        {
            // Save the snk file from the embedded resource to the disk so we can use it when we compile
            using (var resStream = typeof(Program).Assembly.GetManifestResourceStream("GenerateTestPackages." + KeyFileName))
            {
                using (var snkStream = File.Create(KeyFileName))
                {
                    resStream.CopyTo(snkStream);
                }
            }


            var codeProvider   = new CSharpCodeProvider();
            var compilerParams = new CompilerParameters()
            {
                OutputAssembly  = outputPath ?? Path.GetFullPath(GetAssemblyFullPath(package.FullName)),
                CompilerOptions = "/keyfile:" + KeyFileName
            };

            // Add all the dependencies as referenced assemblies
            foreach (DependencyInfo dependency in package.Dependencies)
            {
                compilerParams.ReferencedAssemblies.Add(GetAssemblyFullPath(dependency.FullName));
            }

            // Create the source code and compile it using CodeDom
            var generator = new AssemblySourceFileGenerator()
            {
                Package = package
            };
            CompilerResults results = codeProvider.CompileAssemblyFromSource(compilerParams, generator.TransformText());

            if (results.Errors.HasErrors)
            {
                Console.WriteLine(results.Errors[0]);
            }

            File.Delete(KeyFileName);
        }
Ejemplo n.º 2
0
        static void CreateAssembly(PackageInfo package, string outputPath = null)
        {

            // Save the snk file from the embedded resource to the disk so we can use it when we compile
            using (var resStream = typeof(Program).Assembly.GetManifestResourceStream("GenerateTestPackages." + keyFileName))
            {
                using (var snkStream = File.Create(keyFileName))
                {
                    resStream.CopyTo(snkStream);
                }
            }


            var codeProvider = new CSharpCodeProvider();
            var compilerParams = new CompilerParameters()
            {
                OutputAssembly = outputPath ?? Path.GetFullPath(GetAssemblyFullPath(package.FullName)),
                CompilerOptions = "/keyfile:" + keyFileName
            };

            // Add all the dependencies as referenced assemblies
            foreach (DependencyInfo dependency in package.Dependencies)
            {
                compilerParams.ReferencedAssemblies.Add(GetAssemblyFullPath(dependency.FullName));
            }

            // Create the source code and compile it using CodeDom
            var generator = new AssemblySourceFileGenerator() { Package = package };
            CompilerResults results = codeProvider.CompileAssemblyFromSource(compilerParams, generator.TransformText());

            if (results.Errors.HasErrors)
            {
                Console.WriteLine(results.Errors[0]);
            }

            File.Delete(keyFileName);
        }