public void ShouldFailToBuildAClassWithAValidReferenceIfReferenceLoactionNotSupplied()
 {
     var unreferencedClass = GetCodeFile("ReferencedDependency.cs.txt");
     var buildFiles = new BuildCodeFiles(unreferencedClass, new List<IDependencyInfo>(), new List<IReferenceInfo>());
     var compilationResult = new BuildFilesCompiler().Compile(buildFiles);
     Assert.That(compilationResult.HasErrors);
 }
 public void ShouldBuildASingleEmptyClassWithoutError()
 {
     var emptyClass = GetCodeFile("EmptyClass.cs.txt");
     var buildFiles = new BuildCodeFiles(emptyClass, new List<IDependencyInfo>(), new List<IReferenceInfo>());
     var compilationResult = new BuildFilesCompiler().Compile(buildFiles);
     Assert.That(!compilationResult.HasErrors);
     Assert.That(!string.IsNullOrEmpty(compilationResult.AssemblyLocation));
 }
 public void ShouldBuildAClassWithAValidReferenceIfReferenceLoactionIsSupplied()
 {
     var unreferencedClass = GetCodeFile("ReferencedDependency.cs.txt");
     var referenceInfo = GetReference("ICSharpCode.NRefactory");
     var buildFiles = new BuildCodeFiles(unreferencedClass, new List<IDependencyInfo>(), new List<IReferenceInfo> { referenceInfo });
     var compilationResult = new BuildFilesCompiler().Compile(buildFiles);
     Assert.That(compilationResult.HasErrors);
 }
Esempio n. 4
0
        private void ResolveDependenciesFor(ICodeFileInfo selectedCodeFile)
        {
            var dependencies = wiring.GetDependencyExaminer().ExamineSource(selectedCodeFile, selectedCodeFile.Solution);

            DependencyViewer.DataContext = new
            {
                Dependencies = dependencies.Where(d => !d.IsExternal),
                selectedCodeFile.Declerations,
                selectedCodeFile.Project.References };

            filesToBuild = new BuildCodeFiles(selectedCodeFile, dependencies, selectedCodeFile.Project.References);
        }
Esempio n. 5
0
        public CompilationResult Compile(BuildCodeFiles buildFiles)
        {
            using(var codeDomProvider = new CSharpCodeProvider())
            {
                var fileNames = buildFiles.AllFiles.Select(c => c.FullPath).Distinct().ToList();

                var references = buildFiles.References
                    .Select(reference => reference.FullPath)
                    .ToArray();

                var options = new CompilerParameters();
                options.ReferencedAssemblies.AddRange(references);
                var result = codeDomProvider.CompileAssemblyFromFile(options, fileNames.ToArray());

                var errors = result.Errors.Cast<CompilerError>().Select(error => error.ErrorText);
                return new CompilationResult(errors, result.PathToAssembly);
            }
        }
Esempio n. 6
0
        public CompilationResult Compile(BuildCodeFiles buildFiles)
        {
            using (var codeDomProvider = new CSharpCodeProvider())
            {
                var fileNames = buildFiles.AllFiles.Select(c => c.FullPath).Distinct().ToList();

                var references = buildFiles.References
                                 .Select(reference => reference.FullPath)
                                 .ToArray();

                var options = new CompilerParameters();
                options.ReferencedAssemblies.AddRange(references);
                var result = codeDomProvider.CompileAssemblyFromFile(options, fileNames.ToArray());

                var errors = result.Errors.Cast <CompilerError>().Select(error => error.ErrorText);
                return(new CompilationResult(errors, result.PathToAssembly));
            }
        }