public override void AddProjectToSolution(string projectFullPath) { var msbuildProj = FakeMsBuildProject.Load(projectFullPath); var solutionFile = FakeSolution.Create(SolutionPath); solutionFile.AddProjectToSolution(msbuildProj.Name, msbuildProj.Guid, projectFullPath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)); }
private void AddReferencesToProjects(IEnumerable <ProjectReference> projectReferences) { var solution = FakeSolution.LoadOrCreate(_platform, _language, 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(); } }
public override void AddProjectToSolution(string projectFullPath) { var msbuildProj = FakeMsBuildProject.Load(projectFullPath); var solutionFile = FakeSolution.LoadOrCreate(_platform, SolutionPath); var projectRelativeToSolutionPath = projectFullPath.Replace(Path.GetDirectoryName(SolutionPath) + Path.DirectorySeparatorChar, string.Empty); solutionFile.AddProjectToSolution(_platform, msbuildProj.Name, msbuildProj.Guid, projectRelativeToSolutionPath); }
public override 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, _language, SolutionPath); guid = solution.GetProjectGuids().First(p => p.Key == projectName).Value; } Guid.TryParse(guid, out Guid parsedGuid); return(parsedGuid); }
public override void AddContextItemsToSolution(ProjectInfo projectInfo) { var filesByProject = 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, _language, SolutionPath); var projectRelativeToSolutionPath = project.Replace(Path.GetDirectoryName(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); }