diff options
author | Matt Ward <matt.ward@xamarin.com> | 2017-01-19 19:43:14 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@xamarin.com> | 2017-01-19 19:43:14 +0300 |
commit | 32aa118e226ce2c5338a2609557afb14a2780c44 (patch) | |
tree | b38c7bd8f84b3a288c14f50bb4dd52da061a7868 | |
parent | a1573b3501c8d09835b7e56946faa88cdbc689ff (diff) | |
parent | 864149b076549a73f53b244654f29b2688e23f6a (diff) |
Merge remote-tracking branch 'monodevelop/dotnetcore' into vNext
13 files changed, 128 insertions, 29 deletions
diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreMSBuildProjectTests.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreMSBuildProjectTests.cs index 90fc93ca8e..39280bfb9d 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreMSBuildProjectTests.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreMSBuildProjectTests.cs @@ -346,5 +346,24 @@ namespace MonoDevelop.DotNetCore.Tests Assert.IsTrue (MSBuildProjectHasGlobalProperty ("AssemblyName")); Assert.IsTrue (MSBuildProjectHasGlobalProperty ("RootNamespace")); } + + [Test] + public void WriteProject_SdkProjectHasToolsVersionSetAfterReading_ToolsVersionRemovedOnWriting () + { + CreateMSBuildProject ( + "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + + " <PropertyGroup>\r\n" + + " <OutputType>Exe</OutputType>\r\n" + + " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + + " </PropertyGroup>\r\n" + + "</Project>"); + ReadProject (); + project.Sdk = "Microsoft.NET.Sdk"; + msbuildProject.ToolsVersion = "4.0"; + + WriteProject (); + + Assert.IsNull (msbuildProject.ToolsVersion); + } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs index f7e60357a1..67d819598e 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs @@ -24,8 +24,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; using System.Collections.Generic; using System.Linq; +using MonoDevelop.Projects; using MonoDevelop.Projects.MSBuild; namespace MonoDevelop.DotNetCore @@ -36,6 +38,7 @@ namespace MonoDevelop.DotNetCore bool hasRootNamespace; bool hasAssemblyName; bool hasDescription; + CompileTarget defaultCompileTarget = CompileTarget.Library; public string ToolsVersion { get; private set; } public bool IsOutputTypeDefined { get; private set; } @@ -49,6 +52,10 @@ namespace MonoDevelop.DotNetCore get { return Sdk != null; } } + public CompileTarget DefaultCompileTarget { + get { return defaultCompileTarget; } + } + public void ReadProject (MSBuildProject project) { ToolsVersion = project.ToolsVersion; @@ -85,6 +92,7 @@ namespace MonoDevelop.DotNetCore if (HasSdk) { project.RemoveInternalElements (); + project.ToolsVersion = ToolsVersion; } } @@ -115,5 +123,15 @@ namespace MonoDevelop.DotNetCore return true; } + + public void ReadDefaultCompileTarget (MSBuildProject project) + { + string outputType = project.EvaluatedProperties.GetValue ("OutputType"); + if (!string.IsNullOrEmpty (outputType)) { + if (!Enum.TryParse (outputType, out defaultCompileTarget)) { + defaultCompileTarget = CompileTarget.Library; + } + } + } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs index 9b86559124..bf1e90dd7b 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs @@ -98,7 +98,7 @@ namespace MonoDevelop.DotNetCore dotNetCoreMSBuildProject.ReadProject (msproject); if (!dotNetCoreMSBuildProject.IsOutputTypeDefined) - Project.CompileTarget = CompileTarget.Library; + Project.CompileTarget = dotNetCoreMSBuildProject.DefaultCompileTarget; Project.UseAdvancedGlobSupport = true; } @@ -288,7 +288,37 @@ namespace MonoDevelop.DotNetCore if (dotNetCoreMSBuildProject.AddInternalSdkImports (project, sdkPaths)) { project.Evaluate (); + dotNetCoreMSBuildProject.ReadDefaultCompileTarget (project); } } + + /// <summary> + /// HACK: Remove any C# files found in the intermediate obj directory. This avoids + /// a type system error if a file in the obj directory is modified but the type + /// system does not have that file in the workspace. This can happen if the file + /// was not filtered out initially and added to the project by the wildcard import + /// and then later on after a re-evaluation of the project is filtered out from the + /// source files returned by Project.OnGetSourceFiles. + /// </summary> + protected override async Task<ProjectFile[]> OnGetSourceFiles (ProgressMonitor monitor, ConfigurationSelector configuration) + { + var sourceFiles = await base.OnGetSourceFiles (monitor, configuration); + + return RemoveFilesFromIntermediateDirectory (sourceFiles); + } + + ProjectFile[] RemoveFilesFromIntermediateDirectory (ProjectFile[] files) + { + var filteredFiles = new List<ProjectFile> (); + FilePath intermediateOutputPath = Project.BaseIntermediateOutputPath; + + foreach (var file in files) { + if (!file.FilePath.IsChildPathOf (intermediateOutputPath)) { + filteredFiles.Add (file); + } + } + + return filteredFiles.ToArray (); + } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs index 36ef924747..53a1046d67 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs @@ -67,10 +67,6 @@ namespace MonoDevelop.DotNetCore if (string.IsNullOrEmpty (sdk)) return null; - string toolsVersion = tr.GetAttribute ("ToolsVersion"); - if (toolsVersion != "15.0") - return null; - return sdk; } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs index 78e1ee23ab..1f9550e1fb 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs @@ -126,7 +126,15 @@ namespace MonoDevelop.DotNetCore return project.GetImport (importedProjectFile) != null; } - static string DefaultExcludes = @"$(BaseOutputPath)**;$(BaseIntermediateOutputPath)**;**\*.*proj.user;**\*.*proj;**\*.sln;.*;**\.*\**"; + /// <summary> + /// Use IntermediateOutputPath instead of BaseIntermediateOutputPath since the latter + /// seems to have a full path so the exclude fails to match the include since these + /// are relative paths. IntermediateOutputPath is a relative path however it is not + /// as restrictive as BaseIntermediateOutputPath and will not exclude all files from + /// this directory. A separate filtering is done in DotNetCoreProjectExtension's + /// OnGetSourceFiles to remove files from the BaseIntermediateOutputPath. + /// </summary> + static string DefaultExcludes = @"$(BaseOutputPath)**;$(IntermediateOutputPath)**;**\*.*proj.user;**\*.*proj;**\*.sln;.*;**\.*\**"; // HACK: Temporary workaround. Add wildcard items to the project otherwise the // solution window shows no files. diff --git a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Console/ConsoleProject.csproj b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Console/ConsoleProject.csproj index 5787ed73c5..5e1611f89d 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Console/ConsoleProject.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Console/ConsoleProject.csproj @@ -1,11 +1,8 @@ -<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.0</TargetFramework> </PropertyGroup> - <ItemGroup> - <PackageReference Include="Microsoft.NETCore.App" Version="1.0.3" /> - </ItemGroup> </Project> diff --git a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/EmptyWeb/EmptyWebProject.csproj b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/EmptyWeb/EmptyWebProject.csproj index 505db35118..f71ef36b61 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/EmptyWeb/EmptyWebProject.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/EmptyWeb/EmptyWebProject.csproj @@ -1,21 +1,11 @@ -<Project Sdk="Microsoft.NET.Sdk.Web" ToolsVersion="15.0"> +<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> - <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.0</TargetFramework> - <PreserveCompilationContext>true</PreserveCompilationContext> - </PropertyGroup> - - <PropertyGroup> - <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.NETCore.App" Version="1.0.3" /> - <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.0" /> - <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" /> - <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" /> - <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.0" /> + <PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" /> </ItemGroup> </Project> diff --git a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Library/LibraryProject.csproj b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Library/LibraryProject.csproj index d4b7bb0878..20861435dc 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Library/LibraryProject.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/Templates/Projects/Library/LibraryProject.csproj @@ -1,10 +1,7 @@ -<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard1.4</TargetFramework> </PropertyGroup> - <ItemGroup> - <PackageReference Include="NETStandard.Library" Version="1.6" /> - </ItemGroup> </Project> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs index 8b43070797..7eba9a6cc6 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs @@ -176,7 +176,8 @@ namespace MonoDevelop.PackageManagement public static bool HasPackageReferences (this DotNetProject project)
{
- return project.Items.OfType<ProjectPackageReference> ().Any ();
+ return project.Items.OfType<ProjectPackageReference> ().Any () ||
+ project.MSBuildProject.HasEvaluatedPackageReferences ();
}
public static ProjectPackageReference GetPackageReference (
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectProxy.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectProxy.cs index 06acd72da9..565fd96603 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectProxy.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectProxy.cs @@ -153,7 +153,12 @@ namespace MonoDevelop.PackageManagement public IEnumerable<ProjectPackageReference> GetPackageReferences ()
{
- return DotNetProject.Items.OfType<ProjectPackageReference> ();
+ foreach (var item in DotNetProject.MSBuildProject.GetEvaluatedPackageReferences ()) {
+ yield return item;
+ }
+ foreach (var item in DotNetProject.Items.OfType<ProjectPackageReference> ()) {
+ yield return item;
+ }
}
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MSBuildProjectExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MSBuildProjectExtensions.cs index 37545c9cd8..f1c155b48a 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MSBuildProjectExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MSBuildProjectExtensions.cs @@ -88,5 +88,26 @@ namespace MonoDevelop.PackageManagement {
return project.GetImport (importedProjectFile) != null;
}
+
+ public static IEnumerable<ProjectPackageReference> GetEvaluatedPackageReferences (this MSBuildProject project)
+ {
+ return project.GetEvaluatedPackageReferenceItems ()
+ .Select (ProjectPackageReference.Create);
+ }
+
+ static IEnumerable<IMSBuildItemEvaluated> GetEvaluatedPackageReferenceItems (this MSBuildProject project)
+ {
+ if (project.EvaluatedItems != null) {
+ return project.EvaluatedItems
+ .Where (item => item.Name == "PackageReference");
+ }
+
+ return Enumerable.Empty<IMSBuildItemEvaluated> ();
+ }
+
+ public static bool HasEvaluatedPackageReferences (this MSBuildProject project)
+ {
+ return project.GetEvaluatedPackageReferenceItems ().Any ();
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectPackageReference.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectPackageReference.cs index e2a5c23c1b..5cb98c8379 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectPackageReference.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectPackageReference.cs @@ -27,6 +27,7 @@ using System; using System.Linq; using MonoDevelop.Projects; +using MonoDevelop.Projects.MSBuild; using NuGet.Packaging; using NuGet.Packaging.Core; using NuGet.Versioning; @@ -85,6 +86,20 @@ namespace MonoDevelop.PackageManagement return packageReference; } + internal static ProjectPackageReference Create (string packageId, string version) + { + var package = new PackageIdentity (packageId, new NuGetVersion (version)); + return Create (package); + } + + public static ProjectPackageReference Create (IMSBuildItemEvaluated evaluatedItem) + { + return Create ( + evaluatedItem.Include, + evaluatedItem.Metadata.GetValue ("Version") + ); + } + public override string ToString () { return string.Format ("[PackageReference: {0} {1}]", Include, Metadata.GetValue ("Version")); diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs index 7cd143bda0..7747074f68 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs @@ -148,7 +148,9 @@ namespace MonoDevelop.Projects.MSBuild Environment.CurrentDirectory = Path.GetDirectoryName (file);
var projectRootElement = ProjectRootElement.Create (new XmlTextReader (new StringReader (content)));
projectRootElement.FullPath = file;
- string toolsVersion = projectRootElement.ToolsVersion ?? engine.DefaultToolsVersion;
+ string toolsVersion = projectRootElement.ToolsVersion;
+ if (string.IsNullOrEmpty (toolsVersion))
+ toolsVersion = engine.DefaultToolsVersion;
p = new Project (projectRootElement, engine.GlobalProperties, toolsVersion, engine);
}
}
|