Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Aguilera <luis.aguilera@xamarin.com>2017-07-12 20:44:28 +0300
committerGitHub <noreply@github.com>2017-07-12 20:44:28 +0300
commit6a34636ae67255dab639f2589ee25bfc76693228 (patch)
tree36159c679d2b98c57f5f2d713aa3b6e3d136d698
parentd5c5cdad02e7db3fdc5e8d0de4c80940c626f457 (diff)
parent549cbe1cbbf5bb8aad3c6ac98e8410e3215fb463 (diff)
Merge pull request #2718 from mono/d15-3-bug57840monodevelop-7.1.0.1289
Bug 57840 - Adding .NET Standard project to existing solution/directo…
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs19
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplatingProvider.cs2
-rw-r--r--main/tests/Ide.Tests/ProjectTemplateTests.cs77
3 files changed, 90 insertions, 8 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
index 1b1854e247..5cf26b9d36 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
@@ -44,6 +44,7 @@ using Microsoft.TemplateEngine.Abstractions;
using MonoDevelop.Ide.CodeFormatting;
using MonoDevelop.Core.StringParsing;
using MonoDevelop.Core.Text;
+using MonoDevelop.Projects.Policies;
namespace MonoDevelop.Ide.Templates
{
@@ -147,6 +148,9 @@ namespace MonoDevelop.Ide.Templates
var parameters = GetParameters (solutionTemplate, config);
var templateInfo = solutionTemplate.templateInfo;
var workspaceItems = new List<IWorkspaceFileObject> ();
+
+ var filesBeforeCreation = Directory.GetFiles (config.ProjectLocation, "*", SearchOption.AllDirectories);
+
var result = await templateCreator.InstantiateAsync (
templateInfo,
config.ProjectName,
@@ -174,10 +178,10 @@ namespace MonoDevelop.Ide.Templates
}
//TODO: Once templates support "D396686C-DE0E-4DE6-906D-291CD29FC5DE" use that to load projects
- foreach (var path in Directory.GetFiles (config.ProjectLocation, "*.*proj", SearchOption.AllDirectories)) {
- if (path.EndsWith (".csproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith (".fsproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith (".vbproj", StringComparison.OrdinalIgnoreCase)) {
- workspaceItems.Add (await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem (new Core.ProgressMonitor (), path));
- }
+ foreach (var path in result.ResultInfo.PrimaryOutputs) {
+ var fullPath = Path.Combine (config.ProjectLocation, path.Path);
+ if (Services.ProjectService.IsSolutionItemFile (fullPath))
+ workspaceItems.Add (await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem (new Core.ProgressMonitor (), fullPath));
}
var metadata = new Dictionary<string, string> ();
@@ -215,7 +219,8 @@ namespace MonoDevelop.Ide.Templates
// Format all source files generated during the project creation
foreach (var p in workspaceItems.OfType<Project> ()) {
foreach (var file in p.Files)
- await FormatFile (p, file.FilePath);
+ if (!filesBeforeCreation.Contains ((string)file.FilePath, FilePath.PathComparer)) //Format only newly created files
+ await FormatFile (parentFolder?.Policies ?? p.Policies, file.FilePath);
}
processResult.SetFilesToOpen (filesToOpen);
return processResult;
@@ -249,7 +254,7 @@ namespace MonoDevelop.Ide.Templates
.Where (parameter => parameter.IsValid);
}
- async Task FormatFile (Project p, FilePath file)
+ async Task FormatFile (PolicyContainer policies, FilePath file)
{
string mime = DesktopService.GetMimeTypeForUri (file);
if (mime == null)
@@ -259,7 +264,7 @@ namespace MonoDevelop.Ide.Templates
if (formatter != null) {
try {
var content = await TextFileUtility.ReadAllTextAsync (file);
- var formatted = formatter.FormatText (p.Policies, content.Text);
+ var formatted = formatter.FormatText (policies, content.Text);
if (formatted != null)
TextFileUtility.WriteText (file, formatted, content.Encoding);
} catch (Exception ex) {
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplatingProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplatingProvider.cs
index 0b917b754f..22a3df9eaa 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplatingProvider.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplatingProvider.cs
@@ -82,7 +82,7 @@ namespace MonoDevelop.Ide.Templates
cinfo.ProjectName = config.ProjectName;
cinfo.SolutionName = config.SolutionName;
cinfo.ParentFolder = parentFolder;
- cinfo.ActiveConfiguration = IdeApp.Workspace.ActiveConfiguration;
+ cinfo.ActiveConfiguration = IdeApp.Workspace?.ActiveConfiguration ?? ConfigurationSelector.Default;
cinfo.Parameters = config.Parameters;
return cinfo;
}
diff --git a/main/tests/Ide.Tests/ProjectTemplateTests.cs b/main/tests/Ide.Tests/ProjectTemplateTests.cs
index 890cb68fb7..a1dd4649a2 100644
--- a/main/tests/Ide.Tests/ProjectTemplateTests.cs
+++ b/main/tests/Ide.Tests/ProjectTemplateTests.cs
@@ -31,6 +31,11 @@ using NUnit.Framework;
using UnitTests;
using System.Linq;
using System.Threading.Tasks;
+using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Core;
+using MonoDevelop.Ide.CodeFormatting;
+using MonoDevelop.Core.Text;
+using System;
namespace MonoDevelop.Ide
{
@@ -92,6 +97,78 @@ namespace MonoDevelop.Ide
var myclassFile = sharedAssetsProject.Files.First (f => f.FilePath.FileName == "MyClass.cs");
Assert.AreEqual ("Compile", myclassFile.BuildAction);
}
+
+ async Task FormatFile (Project p, FilePath file)
+ {
+ string mime = DesktopService.GetMimeTypeForUri (file);
+ if (mime == null)
+ return;
+
+ var formatter = CodeFormatterService.GetFormatter (mime);
+ if (formatter != null) {
+ try {
+ var content = await TextFileUtility.ReadAllTextAsync (file);
+ var formatted = formatter.FormatText (p.Policies, content.Text);
+ if (formatted != null)
+ TextFileUtility.WriteText (file, formatted, content.Encoding);
+ } catch (Exception ex) {
+ LoggingService.LogError ("File formatting failed", ex);
+ }
+ }
+ }
+
+ [Test ()]
+ public async Task Bug57840 ()
+ {
+ var templatingService = new TemplatingService ();
+ var mutliplatformLibraryCategory = templatingService.GetProjectTemplateCategories ().Single (c => c.Id == "multiplat")
+ .Categories.Single (c => c.Id == "library")
+ .Categories.Single (c => c.Id == "general");
+ var pclTemplate = mutliplatformLibraryCategory.Templates.Single (t => t.GroupId == "md-project-portable-library").GetTemplate ("C#");
+ var standardTemplate = mutliplatformLibraryCategory.Templates.Single (t => t.GroupId == "Microsoft.Common.Library").GetTemplate ("C#");
+
+ var tempDirectory = Util.CreateTmpDir ("Bug57840Test");
+ var result = await templatingService.ProcessTemplate (pclTemplate, new Ide.Projects.NewProjectConfiguration () {
+ CreateSolution = true,
+ Location = tempDirectory,
+ SolutionName = "Bug57840Test",
+ ProjectName = "Bug57840PclTestProject",
+ CreateProjectDirectoryInsideSolutionDirectory = false
+ }, null);
+
+ var solution = result.WorkspaceItems.OfType<Solution> ().Single ();
+
+ await solution.SaveAsync (Util.GetMonitor ());
+ var project = solution.GetAllProjects ().Single ();
+ project.Policies.Set<TextStylePolicy> (new TextStylePolicy (1, 1, 1, true, true, true, EolMarker.Mac), "text/x-csharp");
+
+ var file = project.Files.Single (f => f.FilePath.FileName == "MyClass.cs").FilePath;
+ var fileContentBeforeFormat = await TextFileUtility.ReadAllTextAsync (file);
+ await FormatFile (project, file);
+ var fileContentAfterFormat = await TextFileUtility.ReadAllTextAsync (file);
+
+ Assert.AreNotEqual (fileContentBeforeFormat.Text, fileContentAfterFormat.Text);//Make sure our weird formatting applied
+
+ solution.Policies.Set<TextStylePolicy> (new TextStylePolicy (3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp");
+
+ var result2 = await templatingService.ProcessTemplate (standardTemplate, new Ide.Projects.NewProjectConfiguration () {
+ CreateSolution = false,
+ Location = solution.BaseDirectory,
+ ProjectName = "Bug57840StandardTestProject",
+ CreateProjectDirectoryInsideSolutionDirectory = false
+ }, solution.RootFolder);
+ await solution.SaveAsync (Util.GetMonitor ());
+ var fileContentAfterSecondProject = await TextFileUtility.ReadAllTextAsync (file);
+ Assert.AreEqual (fileContentAfterSecondProject.Text, fileContentAfterFormat.Text);//Make sure our weird formatting is preserved
+ var standardProject = result2.WorkspaceItems.OfType<DotNetProject> ().Single ();
+ var class1File = standardProject.Files.Single (f => f.FilePath.FileName == "Class1.cs").FilePath;
+ var fileContentAfterCreation = await TextFileUtility.ReadAllTextAsync (class1File);
+ standardProject.Policies.Set<TextStylePolicy> (new TextStylePolicy (3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp");
+ await FormatFile (standardProject, class1File);
+ var fileContentAfterForceFormatting = await TextFileUtility.ReadAllTextAsync (class1File);
+ Assert.AreEqual (fileContentAfterForceFormatting.Text, fileContentAfterCreation.Text,
+ "We expect them to be same because we placed same formatting policy on solution before creataion as after creation on project when we manually formatted.");
+ }
}
}