示例#1
0
        private void AddReferencesToProjects(IEnumerable <ProjectReference> projectReferences)
        {
            var solution     = FakeSolution.LoadOrCreate(Platform, AppModel, Language, FakeGenShellHelper.SolutionPath);
            var projectGuids = solution.GetProjectGuids();

            var groupedReferences = projectReferences.GroupBy(n => n.Project, n => n);

            foreach (var project in groupedReferences)
            {
                var parentProject = FakeMsBuildProject.Load(project.Key);

                foreach (var referenceToAdd in project)
                {
                    var referenceProject = FakeMsBuildProject.Load(referenceToAdd.ReferencedProject);

                    var name = referenceProject.Name;
                    var guid = projectGuids[name];
                    if (guid == "{}")
                    {
                        guid = "{" + Guid.NewGuid().ToString() + "}";
                    }

                    parentProject.AddProjectReference(referenceToAdd.ReferencedProject, guid, name);
                }

                parentProject.Save();
            }
        }
示例#2
0
        public Guid GetProjectGuidByName(string projectName)
        {
            var projectFileName = FindProject(GenContext.Current.DestinationPath);
            var msbuildProj     = FakeMsBuildProject.Load(projectFileName);
            var guid            = msbuildProj.Guid;

            if (string.IsNullOrEmpty(guid))
            {
                var solution = FakeSolution.LoadOrCreate(Platform, AppModel, Language, FakeGenShellHelper.SolutionPath);
                guid = solution.GetProjectGuids().First(p => p.Key == projectName).Value;
            }

            Guid.TryParse(guid, out Guid parsedGuid);
            return(parsedGuid);
        }
示例#3
0
        public void AddContextItemsToSolution(ProjectInfo projectInfo)
        {
            var filesByProject = ProjectHelper.ResolveProjectFiles(projectInfo.ProjectItems);

            var filesForExistingProjects  = filesByProject.Where(k => !projectInfo.Projects.Any(p => p == k.Key));
            var nugetsForExistingProjects = projectInfo.NugetReferences.Where(n => !projectInfo.Projects.Any(p => p == n.Project)).GroupBy(n => n.Project, n => n);
            var sdksForExistingProjects   = projectInfo.SdkReferences.Where(n => !projectInfo.Projects.Any(p => p == n.Project)).GroupBy(n => n.Project, n => n);

            foreach (var files in filesForExistingProjects)
            {
                if (!IsCpsProject(files.Key))
                {
                    AddItems(files.Key, files.Value);
                }
            }

            foreach (var project in nugetsForExistingProjects)
            {
                AddNugetsForProject(project.Key, project);
            }

            foreach (var sdk in sdksForExistingProjects)
            {
                AddSdksForProject(sdk.Key, sdk);
            }

            foreach (var project in projectInfo.Projects)
            {
                var msbuildProj  = FakeMsBuildProject.Load(project);
                var solutionFile = FakeSolution.LoadOrCreate(Platform, AppModel, Language, FakeGenShellHelper.SolutionPath);

                var projectRelativeToSolutionPath = project.Replace(Path.GetDirectoryName(FakeGenShellHelper.SolutionPath) + Path.DirectorySeparatorChar, string.Empty);

                var projGuid = !string.IsNullOrEmpty(msbuildProj.Guid) ? msbuildProj.Guid : Guid.NewGuid().ToString();

                solutionFile.AddProjectToSolution(Platform, AppModel, Language, msbuildProj.Name, projGuid, projectRelativeToSolutionPath, IsCpsProject(project), HasPlatforms(project));

                if (!IsCpsProject(project) && filesByProject.ContainsKey(project))
                {
                    AddItems(project, filesByProject[project]);
                }

                AddNugetsForProject(project, projectInfo.NugetReferences.Where(n => n.Project == project));
                AddSdksForProject(project, projectInfo.SdkReferences.Where(n => n.Project == project));
            }

            AddReferencesToProjects(projectInfo.ProjectReferences);
        }