diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs index 53f691ea0f..9d6c1403ca 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs @@ -5,6 +5,7 @@ // $Revision$ // +using ICSharpCode.SharpDevelop.Internal.Templates; using System; using System.Collections.Generic; using System.IO; @@ -36,18 +37,18 @@ namespace PythonBinding.Tests.Converter string startupObject = "RootNamespace.Main"; string mainSource = "class Foo\r\n" + - "{\r\n" + - " static void Main()\r\n" + - " {\r\n" + - " }\r\n" + - "}"; + "{\r\n" + + " static void Main()\r\n" + + " {\r\n" + + " }\r\n" + + "}"; string main2Source = "class Bar\r\n" + - "{\r\n" + - " static void Main()\r\n" + - " {\r\n" + - " }\r\n" + - "}"; + "{\r\n" + + " static void Main()\r\n" + + " {\r\n" + + " }\r\n" + + "}"; [TestFixtureSetUp] public void SetUpFixture() @@ -75,9 +76,13 @@ namespace PythonBinding.Tests.Converter mockTextEditorProperties.Encoding = Encoding.Unicode; Solution solution = new Solution(); - sourceProject = new MSBuildBasedProject(solution.BuildEngine); + sourceProject = new MSBuildBasedProject( + new ProjectCreateInformation() { + Solution = solution, + OutputProjectFileName = @"d:\projects\test\source.csproj", + ProjectName = "source" + }); sourceProject.Parent = solution; - sourceProject.FileName = @"d:\projects\test\source.csproj"; sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true); mainFile = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs"); targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject); @@ -88,7 +93,7 @@ namespace PythonBinding.Tests.Converter main2File = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs"); targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include); main2File.CopyMetadataTo(targetMain2File); - + convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource); convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs index ad4d5bd22d..0da9cf43da 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs @@ -6,6 +6,7 @@ // using System; +using System.Linq; using System.IO; using System.Text; using ICSharpCode.PythonBinding; @@ -13,7 +14,6 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Project; -using MSBuild = Microsoft.Build.BuildEngine; using NUnit.Framework; using PythonBinding.Tests.Utils; @@ -53,13 +53,14 @@ namespace PythonBinding.Tests { Assert.AreEqual(info.ProjectName, project.Name); } - + [Test] public void Imports() { string[] paths = GetImportPaths(); Assert.Contains(PythonProject.DefaultTargetsFile, paths, "Could not find Python default target. Actual imports: " + GetArrayAsString(paths)); - Assert.Contains(@"$(MSBuildBinPath)\Microsoft.Common.targets", paths, "Could not find Microsoft.Common.targets. Actual imports: " + GetArrayAsString(paths)); + // using MSBuild.Construction, we only see the direct imports + //Assert.Contains(@"$(MSBuildBinPath)\Microsoft.Common.targets", paths, "Could not find Microsoft.Common.targets. Actual imports: " + GetArrayAsString(paths)); } [Test] @@ -84,23 +85,16 @@ namespace PythonBinding.Tests public void DefaultItemTypeForNullPythonFileNameIsCompile() { Assert.AreEqual(ItemType.None, project.GetDefaultItemType(null)); - } + } /// /// Gets the import paths from the project. /// string[] GetImportPaths() { - int count = project.MSBuildProject.Imports.Count; - Microsoft.Build.BuildEngine.Import[] imports = new Microsoft.Build.BuildEngine.Import[count]; - project.MSBuildProject.Imports.CopyTo(imports, 0); - - string[] paths = new string[count]; - for (int i = 0; i < count; ++i) { - Microsoft.Build.BuildEngine.Import import = imports[i]; - paths[i] = import.ProjectPath; + lock (project.SyncRoot) { + return project.MSBuildProjectFile.Imports.Select(i=>i.Project).ToArray(); } - return paths; } /// diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 27c1fdc353..147f95d23f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -43,6 +43,7 @@ ..\..\RequiredLibraries\IronPython.Modules.dll + ..\..\RequiredLibraries\Microsoft.Scripting.dll @@ -61,6 +62,9 @@ 3.0 + + 3.5 + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs index 65c1144714..232b292175 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs @@ -12,7 +12,6 @@ using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Project; -using Microsoft.Build.BuildEngine; namespace PythonBinding.Tests.Utils { diff --git a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs index 66b5b808db..f34349dfc6 100644 --- a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs +++ b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs @@ -5,20 +5,20 @@ // $Revision$ // +using Microsoft.Build.Construction; using System; using System.Collections.Generic; using System.IO; +using System.Runtime.Serialization; using System.Text; using System.Windows.Forms; -using System.Runtime.Serialization; - -using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.Core; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.PrettyPrinter; -using ICSharpCode.SharpDevelop.Project.Commands; +using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Internal.Templates; +using ICSharpCode.SharpDevelop.Project.Commands; namespace ICSharpCode.SharpDevelop.Project.Converter { @@ -73,22 +73,22 @@ namespace ICSharpCode.SharpDevelop.Project.Converter if (sp != null && tp != null) { lock (sp.SyncRoot) { lock (tp.SyncRoot) { - throw new NotImplementedException(); - /* - tp.MSBuildProject.RemoveAllPropertyGroups(); - foreach (MSBuild.BuildPropertyGroup spg in sp.MSBuildProject.PropertyGroups) { - if (spg.IsImported) continue; - MSBuild.BuildPropertyGroup tpg = tp.MSBuildProject.AddNewPropertyGroup(false); + // Remove all PropertyGroups in target project: + foreach (ProjectPropertyGroupElement tpg in tp.MSBuildProjectFile.PropertyGroups) { + tp.MSBuildProjectFile.RemoveChild(tpg); + } + // Copy all PropertyGroups from source project to target project: + foreach (ProjectPropertyGroupElement spg in sp.MSBuildProjectFile.PropertyGroups) { + ProjectPropertyGroupElement tpg = tp.MSBuildProjectFile.AddPropertyGroup(); tpg.Condition = spg.Condition; - foreach (MSBuild.BuildProperty sprop in spg) { - MSBuild.BuildProperty tprop = tpg.AddNewProperty(sprop.Name, sprop.Value); + foreach (ProjectPropertyElement sprop in spg.Properties) { + ProjectPropertyElement tprop = tpg.AddProperty(sprop.Name, sprop.Value); tprop.Condition = sprop.Condition; } } // use the newly created IdGuid instead of the copied one tp.SetProperty(MSBuildBasedProject.ProjectGuidPropertyName, tp.IdGuid); - */ } } } diff --git a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs index 897acbcdcd..a5fda64ca4 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs @@ -69,6 +69,30 @@ namespace ICSharpCode.SharpDevelop.Project userProjectFile = null; } + /// + /// Gets the MSBuild.Construction project file. + /// You must lock on the project's SyncRoot before accessing the MSBuild project file! + /// + public ProjectRootElement MSBuildProjectFile { + get { + if (projectFile == null) + throw new ObjectDisposedException("MSBuildBasedProject"); + return projectFile; + } + } + + /// + /// Gets the MSBuild.Construction project file. + /// You must lock on the project's SyncRoot before accessing the MSBuild project file! + /// + public ProjectRootElement MSBuildUserProjectFile { + get { + if (projectFile == null) + throw new ObjectDisposedException("MSBuildBasedProject"); + return userProjectFile; + } + } + public override int MinimumSolutionVersion { get { lock (SyncRoot) { @@ -331,11 +355,23 @@ namespace ICSharpCode.SharpDevelop.Project } } + /// + /// calls OpenConfiguration for the current configuration + /// ConfiguredProject OpenCurrentConfiguration() { return OpenConfiguration(null, null); } + /// + /// Provides access to the underlying MSBuild.Evaluation project. + /// Usage: + /// using (ConfiguredProject c = OpenCurrentConfiguration()) { + /// // access c.Project only in this block + /// } + /// This method is thread-safe: calling it locks the SyncRoot. You have to dispose + /// the ConfiguredProject instance to unlock the SyncRoot. + /// ConfiguredProject OpenConfiguration(string configuration, string platform) { bool lockTaken = false; @@ -379,7 +415,7 @@ namespace ICSharpCode.SharpDevelop.Project readonly bool unloadProjectOnDispose; public readonly MSBuild.Project Project; - public ConfiguredProject(MSBuildBasedProject parent, MSBuild.Project project, bool unloadProjectOnDispose) + internal ConfiguredProject(MSBuildBasedProject parent, MSBuild.Project project, bool unloadProjectOnDispose) { this.p = parent; this.Project = project;