Beispiel #1
0
        public static MSBuildProj GetProject(string filePath, string targetFramework, bool forceNew, bool build, ILogger logger, bool globalTool = false)
        {
            MSBuildProj project = null;

            var projectDir     = Path.GetDirectoryName(filePath);
            var srcProgramFile = Path.Combine(projectDir, "Program.cs");
            var dstProgramFile = Path.Combine(projectDir, $"{Path.GetFileNameWithoutExtension(filePath)}.cs");

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            if (forceNew && File.Exists(filePath))
            {
                File.Delete(filePath);
                if (File.Exists(dstProgramFile))
                {
                    File.Delete(dstProgramFile);
                }
                FileUtil.TryDeleteDirectory(Path.Combine(Path.GetDirectoryName(filePath), "obj"));
            }

            if (File.Exists(filePath))
            {
                project = MSBuildProj.FromPathAsync(filePath, logger, token).Result;
            }
            else
            {
                project = MSBuildProj.DotNetNewAsync(filePath, logger, token).Result;
                File.Move(srcProgramFile, dstProgramFile);
            }

            Assert.NotNull(project);

            if (!string.IsNullOrEmpty(targetFramework))
            {
                project.TargetFramework = targetFramework;
            }

            if (!globalTool)
            {
                var svcutilPkgVersion = E2ETest.GetSvcutilPkgVersionAndFeed();
                var svcutilPkgRef     = ProjectDependency.FromPackage("dotnet-svcutil-lib", svcutilPkgVersion);
                if (!project.Dependencies.Any(d => d.Equals(svcutilPkgRef)))
                {
                    bool success = project.AddDependency(svcutilPkgRef);
                    Assert.True(success, $"Could not add tool package dependency: dotnet-svcutil-lib.{svcutilPkgVersion}");
                }
            }

            var ret = project.RestoreAsync(logger, token).Result;

            Assert.True(ret.ExitCode == 0, $"Project package restore failed:{Environment.NewLine}{ret.OutputText}{logger}");

            if (build)
            {
                ret = project.BuildAsync(logger, token).Result;
                Assert.True(ret.ExitCode == 0, $"Project build failed:{Environment.NewLine}{ret.OutputText}{logger}");
            }

            return(project);
        }
        public static void Load()
        {
            string dependenciesJson = File.ReadAllText(dependenciesFilePath);
            string packagesJson     = File.ReadAllText(packagesFilePath);

            ProjectDependency projDependency             = JsonConvert.DeserializeObject <ProjectDependency>(dependenciesJson);
            Dictionary <string, List <string> > packages = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(packagesJson);

            ResolveDependencies(projDependency.dependencies, packages);
            Console.WriteLine("Done!");
        }
Beispiel #3
0
        private void HoistFrameworkAssembliesForDesktopFrameworks(
            ProjectDependency projectDependency,
            ProjectRootElement outputMSBuildProject)
        {
            var targetFrameworks = ProjectReader
                                   .GetProject(projectDependency.ProjectFilePath)
                                   .GetTargetFrameworks().Where(p => !p.FrameworkName.IsPackageBased);

            foreach (var targetFramework in targetFrameworks)
            {
                HoistFrameworkAssemblies(targetFramework, outputMSBuildProject);
            }
        }
Beispiel #4
0
    private static Project CreateProject()
    {
        var project = new Project()
        {
            Id = 1
        };

        project.Dependencies = new List <ProjectDependency>();
        for (int projectId = 2; projectId < 10; projectId++)
        {
            var dependency = new ProjectDependency()
            {
                Project = project, Dependency = new Project()
                {
                    Id = projectId
                }
            };
            project.Dependencies.Add(dependency);
        }
        return(project);
    }
Beispiel #5
0
        public void UpdateServiceRefBasic(string referenceFolderName, bool bootstrapping)
        {
            this_TestCaseName = "UpdateServiceRefBasic";
            TestFixture();
            var testCaseName = referenceFolderName;

            InitializeE2E(testCaseName, createUniqueProject: true, sdkVersion: g_SdkVersion);

            var paramsFile = SetupServiceReferenceFolder("dotnet-svcutil.params.json", referenceFolderName);

            if (bootstrapping)
            {
                var updateOptions = UpdateOptions.FromFile(paramsFile);
                // this forces bootstrapping of svcutil as the project reference is not available at runtime.
                updateOptions.References.Add(ProjectDependency.FromPackage("Newtonsoft.Json", "*"));
                updateOptions.Save(paramsFile);
            }

            var options = "-u -v minimal";

            TestSvcutil(options, expectSuccess: true);
        }
Beispiel #6
0
        private string SetupProjectDependencies()
        {
            var libProjPath  = Path.Combine(this_TestGroupOutputDir, "TypesLib", "TypesLib.csproj");
            var binProjPath  = Path.Combine(this_TestGroupOutputDir, "BinLib", "BinLib.csproj");
            var assemblyPath = Path.Combine(Path.GetDirectoryName(binProjPath), "bin", "Debug", "netstandard1.3", "BinLib.dll");

            if (!File.Exists(assemblyPath))
            {
                var typeReuseProjectsPath = Path.Combine(g_TestCasesDir, "TypeReuse");

                FileUtil.CopyDirectory(typeReuseProjectsPath, this_TestGroupOutputDir);
                CreateGlobalJson(this_TestGroupOutputDir, this_TestCaseProject.SdkVersion);

                MSBuildProj binProj = MSBuildProj.FromPathAsync(binProjPath, null, CancellationToken.None).Result;
                ProcessRunner.ProcessResult result = binProj.BuildAsync(true, null, CancellationToken.None).Result;
                Assert.True(result.ExitCode == 0, result.OutputText);
            }

            Assert.True(File.Exists(binProjPath), $"{nameof(binProjPath)} not initialized!");
            Assert.True(File.Exists(libProjPath), $"{nameof(libProjPath)} not initialized!");

            this_TestCaseProject.AddDependency(ProjectDependency.FromAssembly(assemblyPath));
            this_TestCaseProject.AddDependency(ProjectDependency.FromProject(libProjPath));
            this_TestCaseProject.SaveAsync(this_TestCaseLogger, CancellationToken.None).Wait();

            ProcessRunner.ProcessResult ret = this_TestCaseProject.BuildAsync(true, this_TestCaseLogger, CancellationToken.None).Result;
            Assert.True(ret.ExitCode == 0, ret.OutputText);

            // keep the boostrapper projects in the outputs to be evaluated against baselines.
            this_TestCaseBootstrapDir = this_TestCaseOutputDir;
            Directory.CreateDirectory(Path.Combine(this_TestCaseBootstrapDir, "SvcutilBootstrapper"));

            var uri = PathHelper.GetRelativePath(Path.Combine(this_TestGroupOutputDir, "TypeReuseSvc.wsdl"), new DirectoryInfo(this_TestCaseOutputDir));

            return(uri);
        }
        private void GenerateTableForProjects(Project[] projs)
        {
            var table = new DataTable();

            // Generate columns
            var columns = new DataColumn[projs.Length + 1];

            columns[0]          = new DataColumn(@"Projects\Deps");
            columns[0].DataType = typeof(string);

            for (int i = 0; i < projs.Length; i++)
            {
                columns[i + 1]          = new DataColumn(projs[i].Name);
                columns[i + 1].DataType = typeof(ProjectDependency);
            }

            table.Columns.AddRange(columns);

            // Generate rows
            for (int i = 0; i < projs.Length; i++)
            {
                DataRow row = table.NewRow();
                row[0] = columns[i + 1].ColumnName;
                for (int j = 0; j < projs.Length; j++)
                {
                    if (j == i)
                    {
                        row[j + 1] = ProjectDependency.Invalid;
                    }
                    else
                    {
                        //row[j + 1] = projs[i].DepProjects.Has(projs[j]) ? ProjectDependency.Direct : DataGridViewTriState.False;

                        ProjectDependency dep = ProjectDependency.None;
                        if (projs[i].DepProjects.Has(projs[j]))
                        {
                            dep = ProjectDependency.Direct;
                        }
                        else if (projs[i].ProjectTree.Has(projs[j]))
                        {
                            dep = ProjectDependency.Indirect;
                        }
                        else if (projs[i].Parents.Has(projs[j]))
                        {
                            dep = ProjectDependency.Invalid;
                        }
                        else
                        {
                            dep = ProjectDependency.None;
                        }
                        row[j + 1] = dep;
                    }
                }
                table.Rows.Add(row);
            }

            MatrixDataGridView.DataSource          = table;
            MatrixDataGridView.ColumnHeadersHeight = 10;
            // resize columns
            MatrixDataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            for (int i = 1; i < columns.Length; i++)
            {
                MatrixDataGridView.Columns[i].Width = box_size + 2 * box_offset;
            }
        }
Beispiel #8
0
 public static ProjectConfig Resolve(ProjectDatabase manager, ProjectDependency dependency)
 {
     return(manager.GetPackage(dependency.ProjectName).
            GetInstallTarget(dependency.ProjectVersion == "ANY" ? null : dependency.ProjectVersion));
 }
Beispiel #9
0
 public static ProjectConfig Resolve(string repository, ProjectDependency dependency)
 {
     return(s_Managers[repository].
            GetPackage(dependency.ProjectName).
            GetInstallTarget(dependency.ProjectVersion == "ANY" ? null : dependency.ProjectVersion));
 }
Beispiel #10
0
        private ProjectDependency Parse(ProjectSourceCodes sourceCode)
        {
            var projectDependency = new ProjectDependency
            {
                ProjectName = sourceCode.ProjectName
            };

            ProjectSourceCodes.File currentFile = null;
            try
            {
                var dependencies = projectDependency.Dependencies = new Dictionary <string, Dictionary <string, HashSet <string> > >();
                var allFiles     = sourceCode?.Files ?? new ProjectSourceCodes.File[] { };
                foreach (var file in allFiles)
                {
                    currentFile = file;
                    var projectsModels = codeParser.ExtractDependencies(file.SourceCode);

                    foreach (var projectModels in projectsModels)
                    {
                        var projectName = projectModels.Key;
                        var models      = projectModels.Value;

                        if (dependencies.TryAdd(projectName, null))
                        {
                            var files = new HashSet <string>
                            {
                                file.Name
                            };

                            dependencies[projectName] = models.ToDictionary(
                                x => x,
                                x => files
                                );
                        }
                        else
                        {
                            var currentProject = dependencies[projectName];
                            foreach (var model in models)
                            {
                                if (currentProject.ContainsKey(model))
                                {
                                    currentProject[model].Add(file.Name);
                                }
                                else
                                {
                                    var files = new HashSet <string>
                                    {
                                        file.Name
                                    };
                                    currentProject.Add(model, files);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                error.Status = CodeErrors.HasError;
                error.Class  = $"{nameof(Parser)}";
                error.Method = $"{nameof(Parse)}({nameof(ProjectSourceCodes)} sourceCode)";

                logger.Error(e, $"Parsing error in file [{currentFile?.Name}]!");
            }
            return(projectDependency);
        }
        public static ProjectDesignator FromProjectDependency(ProjectDependency projectDependency)
        {
            if (projectDependency == null) throw new ArgumentNullException("projectDependency");

              return new ProjectDesignator(projectDependency.ProjectName, projectDependency.ProjectConfiguration);
        }