diff options
author | Matt Ward <matt.ward@microsoft.com> | 2019-05-09 19:59:46 +0300 |
---|---|---|
committer | Matt Ward <ward.matt@gmail.com> | 2019-05-10 17:38:08 +0300 |
commit | 72dab90aabbd5a792e10ff6b7b655f4bf193366b (patch) | |
tree | bf7fec901e2173ee71c5ef975e6ae54177bdce00 /main/src/addins/MonoDevelop.DotNetCore | |
parent | fe97c47908d20dd6a9f2443ecbc76847f6638a46 (diff) |
[DotNetCore] Split out SDK style project support
Move SDK style project specific code out of the .NET Core addin into
MonoDevelop.Core. NuGet specific code has been moved into the NuGet
addin. The DotNetCoreProjectExtension was supporting all SDK style
projects now it supports .NET Core and .NET Standard projects that
use the .NET Core SDK.
Fixes VSTS #830544 - Split out SDK style project support from the
.NET Core addin
Diffstat (limited to 'main/src/addins/MonoDevelop.DotNetCore')
16 files changed, 26 insertions, 1785 deletions
diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs index 0935ab5f0b..0ffb098bd9 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs @@ -28,6 +28,7 @@ using System.Collections.Generic; using System.Linq; using MonoDevelop.Core.Assemblies; using MonoDevelop.Ide.Templates; +using MonoDevelop.Projects; namespace MonoDevelop.DotNetCore.Templating { @@ -155,7 +156,7 @@ namespace MonoDevelop.DotNetCore.Templating var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworks ().FirstOrDefault (); if (highestFramework != null) { - Parameters ["framework"] = highestFramework.Id.GetShortFrameworkName (); + Parameters ["framework"] = highestFramework.Id.ShortName; } else { Parameters ["framework"] = "netcoreapp1.1"; } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs index 765fb36b14..8d87500de2 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs @@ -30,6 +30,7 @@ using MonoDevelop.Core; using MonoDevelop.Core.Assemblies; using MonoDevelop.DotNetCore.Gui; using MonoDevelop.Ide.Templates; +using MonoDevelop.Projects; namespace MonoDevelop.DotNetCore.Templating { @@ -104,7 +105,7 @@ namespace MonoDevelop.DotNetCore.Templating { var framework = targetFrameworks [selectedTargetFrameworkIndex]; - wizard.Parameters ["Framework"] = framework.Id.GetShortFrameworkName (); + wizard.Parameters ["Framework"] = framework.Id.ShortName; foreach (var param in parameters) { wizard.Parameters [param] = "false"; diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj index 95d8150c4b..70fbc9b701 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj @@ -19,7 +19,6 @@ <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\DotNetCoreProjectTests.cs" /> - <Compile Include="MonoDevelop.DotNetCore.Tests\DotNetCoreMSBuildProjectTests.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\DotNetCoreVersionTests.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\DotNetCoreSdkTests.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\DotNetCoreProjectTemplateTests.cs" /> 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 deleted file mode 100644 index bd7cf6e50d..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreMSBuildProjectTests.cs +++ /dev/null @@ -1,568 +0,0 @@ -// -// DotNetCoreMSBuildProjectTests.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Linq; -using MonoDevelop.Core.Assemblies; -using MonoDevelop.Projects.MSBuild; -using NUnit.Framework; - -namespace MonoDevelop.DotNetCore.Tests -{ - [TestFixture] - class DotNetCoreMSBuildProjectTests - { - DotNetCoreMSBuildProject project; - MSBuildProject msbuildProject; - - void CreateMSBuildProject (string xml, string fileName = @"MyProject.csproj") - { - msbuildProject = new MSBuildProject (); - msbuildProject.FileName = fileName; - msbuildProject.LoadXml (xml); - - project = new DotNetCoreMSBuildProject (); - } - - void AddGlobalPropertyToMSBuildProject (string name, string value, string defaultValue = null) - { - msbuildProject - .GetGlobalPropertyGroup () - .SetValue (name, value, defaultValue); - } - - string GetPropertyValueFromMSBuildProject (string name) - { - return msbuildProject - .GetGlobalPropertyGroup () - .GetValue (name); - } - - bool MSBuildProjectHasGlobalProperty (string name) - { - return msbuildProject - .GetGlobalPropertyGroup () - .HasProperty (name); - } - - void ReadProject (string frameworkMoniker = ".NETCoreApp,Version=v1.0") - { - var moniker = TargetFrameworkMoniker.Parse (frameworkMoniker); - project.ReadProjectHeader (msbuildProject); - project.ReadProject (msbuildProject, moniker); - } - - void WriteProject (string frameworkMoniker = ".NETCoreApp,Version=v1.0") - { - var moniker = TargetFrameworkMoniker.Parse (frameworkMoniker); - project.WriteProject (msbuildProject, moniker); - } - - [Test] - public void ReadProject_ToolsVersionDefined () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - "</Project>"); - - ReadProject (); - project.HasSdk = true; - - Assert.AreEqual ("15.0", project.ToolsVersion); - Assert.IsFalse (project.IsOutputTypeDefined); - Assert.IsTrue (project.HasSdk); - } - - [Test] - public void ReadProject_OutputTypeDefined () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - - ReadProject (); - - Assert.IsTrue (project.IsOutputTypeDefined); - Assert.AreEqual ("netcoreapp1.0", project.TargetFrameworks.Single ()); - } - - [Test] - public void ReadProject_ExplicityReferences () - { - CreateMSBuildProject ( - "<Project ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - " <Import Sdk=\"Microsoft.NET.Sdk\" Project=\"Sdk.targets\" />" + - "</Project>"); - msbuildProject.Evaluate (); - - ReadProject (); - - Assert.That (msbuildProject.GetReferencedSDKs (), Is.Not.Empty); - } - - [Test] - public void WriteProject_ProjectGuidAddedAndToolsVersionChanged_ProjectGuidIsRemovedAndToolsVersionReset () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - - msbuildProject.ToolsVersion = "4.0"; - AddGlobalPropertyToMSBuildProject ("ProjectGuid", "{111}"); - WriteProject (); - - Assert.AreEqual ("15.0", msbuildProject.ToolsVersion); - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("ProjectGuid")); - } - - [Test] - public void WriteProject_OutputTypeLibraryIsAdded_OutputTypeIsRemoved () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - - msbuildProject.ToolsVersion = "4.0"; - AddGlobalPropertyToMSBuildProject ("OutputType", "Library"); - WriteProject (); - - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("OutputType")); - } - - [Test] - public void WriteProject_OutputTypeLibraryIsDefinedWhenRead_OutputTypeIsNotRemoved () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - - WriteProject (); - - Assert.IsTrue (MSBuildProjectHasGlobalProperty ("OutputType")); - } - - [Test] - public void WriteProject_DefaultTargetsAdded_DefaultTargetsIsSetToNull () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - msbuildProject.DefaultTargets = "Build"; - - WriteProject (); - - Assert.IsNull (msbuildProject.DefaultTargets); - } - - [Test] - public void WriteProject_DescriptionAdded_RemovedOnWritingSinceDefaultIsUsed () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - AddGlobalPropertyToMSBuildProject ("Description", "Package Description", string.Empty); - - WriteProject (); - - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("Description")); - } - - [Test] - public void WriteProject_DescriptionInOriginalProjectFile_NotRemovedOnWriting () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " <Description>Test</Description>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - - WriteProject (); - - Assert.IsTrue (MSBuildProjectHasGlobalProperty ("Description")); - } - - [Test] - public void WriteProject_DescriptionNotInOriginalProjectFileAndNonDefaultValueUsed_NotRemovedOnWriting () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - AddGlobalPropertyToMSBuildProject ("Description", "Test", string.Empty); - - WriteProject (); - - Assert.AreEqual ("Test", GetPropertyValueFromMSBuildProject ("Description")); - } - - [Test] - public void WriteProject_TargetFrameworkInformationAdded_RemovedOnWriting () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - AddGlobalPropertyToMSBuildProject ("TargetFrameworkVersion", "1.0"); - AddGlobalPropertyToMSBuildProject ("TargetFrameworkIdentifier", ".NETCoreApp"); - - WriteProject (); - - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("TargetFrameworkVersion")); - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("TargetFrameworkIdentifier")); - } - - [Test] - public void WriteProject_AssemblyNameAndRootNamespaceAddedButSameAsProjectName_RemovedOnWriting () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>", - "Test.csproj" - ); - ReadProject (); - AddGlobalPropertyToMSBuildProject ("AssemblyName", "Test"); - AddGlobalPropertyToMSBuildProject ("RootNamespace", "Test"); - - WriteProject (); - - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("AssemblyName")); - Assert.IsFalse (MSBuildProjectHasGlobalProperty ("RootNamespace")); - } - - [Test] - public void WriteProject_AssemblyNameAndRootNamespaceInOriginalProjectFile_NotRemovedOnWriting () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " <AssemblyName>Test</AssemblyName>\r\n" + - " <RootNamespace>Test</RootNamespace>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - ReadProject (); - - WriteProject (); - - 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.HasSdk = true; - msbuildProject.ToolsVersion = "4.0"; - - WriteProject (); - - Assert.IsNull (msbuildProject.ToolsVersion); - } - - [Test] - public void WriteProject_NewProjectReferenceAddedWithNameAndProjectMetadata_ProjectReferenceSavedWithJustIncludeNotNameAndProject () - { - 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.HasSdk = true; - var projectReferenceItem = msbuildProject.AddNewItem ("ProjectReference", @"Lib\Lib.csproj"); - projectReferenceItem.Metadata.SetValue ("Name", "Lib"); - projectReferenceItem.Metadata.SetValue ("Project", "{F109E7DF-F561-4CD6-A46E-CFB27A8B6F2C}"); - - WriteProject (); - - var projectReferenceSaved = msbuildProject.GetAllItems () - .FirstOrDefault (item => item.Name == "ProjectReference"); - - Assert.IsFalse (projectReferenceSaved.Metadata.HasProperty ("Name")); - Assert.IsFalse (projectReferenceSaved.Metadata.HasProperty ("Project")); - Assert.AreEqual (@"Lib\Lib.csproj", projectReferenceSaved.Include); - } - - [Test] - public void WriteProject_TargetFrameworkVersionChanged_TargetFrameworkUpdated () - { - 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>"); - msbuildProject.Evaluate (); - ReadProject (); - project.HasSdk = true; - - WriteProject (".NETCoreApp,Version=v1.1"); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual ("netcoreapp1.1", savedFramework); - } - - [Test] - public void WriteProject_TargetFrameworkVersionChangedThenChangedBackAgain_OriginalTargetFrameworkUsedInProject () - { - 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>"); - msbuildProject.Evaluate (); - ReadProject (); - project.HasSdk = true; - - WriteProject (".NETCoreApp,Version=v1.1"); - WriteProject (".NETCoreApp,Version=v1.0"); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual ("netcoreapp1.0", savedFramework); - } - - [Test] - public void WriteProject_NetStandardTargetFrameworkVersionChanged_TargetFrameworkUpdated () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netstandard1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - ReadProject (".NET Standard,Version=v1.0"); - project.HasSdk = true; - - WriteProject (".NETStandard,Version=v1.6"); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual ("netstandard1.6", savedFramework); - } - - [Test] - public void WriteProject_NetFrameworkVersionChanged_TargetFrameworkUpdated () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>net45</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - ReadProject (); - project.HasSdk = true; - - WriteProject (".NETFramework,Version=v4.6"); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual ("net46", savedFramework); - } - - [Test] - public void WriteProject_ProjectDefinesMultipleTargetFrameworksAndTargetFrameworkVersionChanged_TargetFrameworksUpdated () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFrameworks>netcoreapp1.0;net45</TargetFrameworks>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - ReadProject (); - project.HasSdk = true; - - WriteProject (".NETCoreApp,Version=v1.1"); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFrameworks"); - Assert.AreEqual ("netcoreapp1.1;net45", savedFramework); - } - - [Test] - public void WriteProject_AssemblyNameAndRootNamespaceAddedDifferentToProjectName_AssemblyNameAndRootNamespaceSaved () - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\" ToolsVersion=\"15.0\">\r\n" + - " <PropertyGroup>\r\n" + - " <OutputType>Exe</OutputType>\r\n" + - " <TargetFramework>netcoreapp1.0</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>", - "MyProject.csproj"); - ReadProject (); - AddGlobalPropertyToMSBuildProject ("AssemblyName", "NewAssemblyName"); - AddGlobalPropertyToMSBuildProject ("RootNamespace", "NewRootNamespace"); - - WriteProject (); - - Assert.AreEqual ("NewAssemblyName", GetPropertyValueFromMSBuildProject ("AssemblyName")); - Assert.AreEqual ("NewRootNamespace", GetPropertyValueFromMSBuildProject ("RootNamespace")); - } - - [TestCase ("netcoreapp1.0", ".NETCoreApp,Version=v1.0")] - [TestCase ("netcoreapp10", ".NETCoreApp,Version=v1.0")] - [TestCase ("NetCoreApp1.0", ".NETCoreApp,Version=v1.0")] - [TestCase ("net461", ".NETFramework,Version=v4.6.1")] - [TestCase ("net4.6.1", ".NETFramework,Version=v4.6.1")] - [TestCase ("Net461", ".NETFramework,Version=v4.6.1")] - [TestCase ("NET461", ".NETFramework,Version=v4.6.1")] - [TestCase ("netstandard2.0", ".NETStandard,Version=v2.0")] - [TestCase ("netstandard20", ".NETStandard,Version=v2.0")] - [TestCase ("NetStandard2.0", ".NETStandard,Version=v2.0")] - [TestCase ("tizen40", "Tizen,Version=v4.0")] - [TestCase ("tizen4.0", "Tizen,Version=v4.0")] - [TestCase ("Tizen4.0", "Tizen,Version=v4.0")] - public void WriteProject_ProjectTargetFrameworkUnchanged_TargetFrameworkPropertyNotModified ( - string shortFrameworkName, - string fullFrameworkName) - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + - " <PropertyGroup>\r\n" + - " <TargetFramework>" + shortFrameworkName + "</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - ReadProject (fullFrameworkName); - - WriteProject (fullFrameworkName); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual (shortFrameworkName, savedFramework); - } - - [TestCase ("netcoreapp1.0", ".NETCoreApp,Version=v1.0", ".NETCoreApp,Version=v1.1", "netcoreapp1.1")] - [TestCase ("netcoreapp10", ".NETCoreApp,Version=v1.0", ".NETCoreApp,Version=v1.1", "netcoreapp11")] - [TestCase ("NetCoreApp1.0", ".NETCoreApp,Version=v1.0", ".NETCoreApp,Version=v1.1", "NetCoreApp1.1")] - [TestCase ("net461", ".NETFramework,Version=v4.6.1", ".NETFramework,Version=v4.7.1", "net471")] - [TestCase ("net4.6.1", ".NETFramework,Version=v4.6.1", ".NETFramework,Version=v4.7.1", "net4.7.1")] - [TestCase ("Net461", ".NETFramework,Version=v4.6.1", ".NETFramework,Version=v4.7.1", "Net471")] - [TestCase ("NET461", ".NETFramework,Version=v4.6.1", ".NETFramework,Version=v4.7.1", "NET471")] - [TestCase ("netstandard2.0", ".NETStandard,Version=v2.0", ".NETStandard,Version=v1.1", "netstandard1.1")] - [TestCase ("netstandard20", ".NETStandard,Version=v2.0", ".NETStandard,Version=v1.1", "netstandard11")] - [TestCase ("NetStandard2.0", ".NETStandard,Version=v2.0", ".NETStandard,Version=v1.1", "NetStandard1.1")] - [TestCase ("tizen40", "Tizen,Version=v4.0", "Tizen,Version=v4.1", "tizen41")] - [TestCase ("tizen4.0", "Tizen,Version=v4.0", "Tizen,Version=v4.1", "tizen4.1")] - [TestCase ("Tizen4.0", "Tizen,Version=v4.0", "Tizen,Version=v4.1", "Tizen4.1")] - - // Changing the target framework name should not happen in practice. - [TestCase ("netcoreapp1.0", ".NETCoreApp,Version=v1.0", ".NETFramework,Version=v4.6.1", "net461")] // Use default dotted version format for .NETFramework - [TestCase ("net461", ".NETFramework,Version=v4.6.1", ".NETCoreApp,Version=v1.1", "netcoreapp1.1")] // Use default dotted format for .NET Core. - [TestCase ("netcoreapp1.0", ".NETCoreApp,Version=v1.0", ".NETStandard,Version=v1.1", "netstandard1.1")] - [TestCase ("netcoreapp10", ".NETCoreApp,Version=v1.0", ".NETStandard,Version=v1.0", "netstandard1.0")] - public void WriteProject_ProjectTargetFrameworkChanged_TargetFrameworkPropertyModified ( - string shortFrameworkName, - string originalFullFrameworkName, - string finalFullFrameworkName, - string expectedShortFrameworkName) - { - CreateMSBuildProject ( - "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n" + - " <PropertyGroup>\r\n" + - " <TargetFramework>" + shortFrameworkName + "</TargetFramework>\r\n" + - " </PropertyGroup>\r\n" + - "</Project>"); - msbuildProject.Evaluate (); - ReadProject (originalFullFrameworkName); - - WriteProject (finalFullFrameworkName); - - string savedFramework = msbuildProject.GetGlobalPropertyGroup () - .GetValue ("TargetFramework"); - Assert.AreEqual (expectedShortFrameworkName, savedFramework); - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj index 15bd741d79..eec18e2e11 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj @@ -27,14 +27,8 @@ <Compile Include="MonoDevelop.DotNetCore\DotNetCoreExecutionHandler.cs" /> <Compile Include="MonoDevelop.DotNetCore.Templating\DotNetCoreProjectTemplateWizard.cs" /> <Compile Include="MonoDevelop.DotNetCore\DotNetCoreNotInstalledDialog.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreProjectFileRenamedHandler.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreProjectReloadMonitor.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreProjectReader.cs" /> - <Compile Include="MonoDevelop.DotNetCore\MSBuildProjectExtensions.cs" /> <Compile Include="MonoDevelop.DotNetCore\DotNetCoreSdkPaths.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreMSBuildProject.cs" /> <Compile Include="MonoDevelop.DotNetCore\DotNetCoreCanReferenceProjectExtension.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreProjectBuilderMaintainer.cs" /> <Compile Include="MonoDevelop.DotNetCore\DotNetCliToolReference.cs" /> <Compile Include="MonoDevelop.DotNetCore\DotNetCoreRuntimeOptionsPanel.cs" /> <Compile Include="MonoDevelop.DotNetCore.Gui\DotNetCoreRuntimeOptionsPanelWidget.cs" /> @@ -46,7 +40,6 @@ <Compile Include="MonoDevelop.DotNetCore\DummyMSBuildOptionsPanel.cs" /> <Compile Include="MonoDevelop.DotNetCore\TargetFrameworkMonikerExtensions.cs" /> <Compile Include="MonoDevelop.DotNetCore\FilePathExtensions.cs" /> - <Compile Include="MonoDevelop.DotNetCore\MSBuildPropertyGroupExtensions.cs" /> <Compile Include="MonoDevelop.DotNetCore.NodeBuilders\ProjectDependenciesNode.cs" /> <Compile Include="MonoDevelop.DotNetCore\ProjectReferenceExtensions.cs" /> <Compile Include="MonoDevelop.DotNetCore.NodeBuilders\ProjectDependenciesNodeBuilder.cs" /> @@ -86,7 +79,6 @@ <Compile Include="MonoDevelop.DotNetCore.Gui\GtkDotNetCoreProjectTemplateWizardPageWidget.cs" /> <Compile Include="gtk-gui\MonoDevelop.DotNetCore.Gui.GtkDotNetCoreProjectTemplateWizardPageWidget.cs" /> <Compile Include="MonoDevelop.DotNetCore\MSBuildSdksPathGlobalPropertyProvider.cs" /> - <Compile Include="MonoDevelop.DotNetCore\DotNetCoreShortTargetFramework.cs" /> <Compile Include="MonoDevelop.DotNetCore.Templating\DotNetCoreProjectTemplateStringTagProvider.cs" /> <Compile Include="MonoDevelop.DotNetCore.Gui\DotNetCoreSdkLocationPanel.cs" /> <Compile Include="MonoDevelop.DotNetCore.Gui\DotNetCoreSdkLocationWidget.cs" /> diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs deleted file mode 100644 index 0034e373fd..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreMSBuildProject.cs +++ /dev/null @@ -1,177 +0,0 @@ -// -// DotNetCoreMSBuildProject.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// 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.Core.Assemblies; -using MonoDevelop.PackageManagement; -using MonoDevelop.Projects; -using MonoDevelop.Projects.MSBuild; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreMSBuildProject - { - List<string> targetFrameworks; - bool hasRootNamespace; - bool hasAssemblyName; - bool hasDescription; - CompileTarget defaultCompileTarget = CompileTarget.Library; - TargetFrameworkMoniker targetFrameworkMoniker; - - public string ToolsVersion { get; private set; } - public bool IsOutputTypeDefined { get; private set; } - - public IEnumerable<string> TargetFrameworks => targetFrameworks; - - public bool HasSdk { get; set; } - - public bool HasToolsVersion () => !string.IsNullOrEmpty (ToolsVersion); - - public CompileTarget DefaultCompileTarget => defaultCompileTarget; - - /// <summary> - /// Ensure MSBuildProject has ToolsVersion set to 15.0 so the correct - /// MSBuild targets are imported. - /// </summary> - public void ReadProjectHeader (MSBuildProject project) - { - ToolsVersion = project.ToolsVersion; - if (!HasToolsVersion ()) - project.ToolsVersion = "15.0"; - } - - public void ReadProject (MSBuildProject project, TargetFrameworkMoniker framework) - { - IsOutputTypeDefined = project.IsOutputTypeDefined (); - targetFrameworks = project.GetTargetFrameworks ().ToList (); - hasRootNamespace = project.HasGlobalProperty ("RootNamespace"); - hasAssemblyName = project.HasGlobalProperty ("AssemblyName"); - hasDescription = project.HasGlobalProperty ("Description"); - - targetFrameworkMoniker = framework; - - ReadDefaultCompileTarget (project); - } - - public void WriteProject (MSBuildProject project, TargetFrameworkMoniker framework) - { - var globalPropertyGroup = project.GetGlobalPropertyGroup (); - globalPropertyGroup.RemoveProperty ("ProjectGuid"); - globalPropertyGroup.RemoveProperty ("TargetFrameworkIdentifier"); - globalPropertyGroup.RemoveProperty ("TargetFrameworkVersion"); - - if (!IsOutputTypeDefined) - RemoveOutputTypeIfHasDefaultValue (project, globalPropertyGroup); - - RemoveMSBuildProjectNameDerivedProperties (globalPropertyGroup); - - if (!hasDescription) - globalPropertyGroup.RemovePropertyIfHasDefaultValue ("Description", "Package Description"); - - project.DefaultTargets = null; - - project.RemoveExtraProjectReferenceMetadata (); - - UpdateTargetFramework (project, framework); - - if (HasToolsVersion ()) - project.ToolsVersion = ToolsVersion; - - if (HasSdk) { - project.ToolsVersion = ToolsVersion; - } - } - - static void RemoveOutputTypeIfHasDefaultValue (MSBuildProject project, MSBuildPropertyGroup globalPropertyGroup) - { - string outputType = project.EvaluatedProperties.GetValue ("OutputType"); - if (string.IsNullOrEmpty (outputType)) { - globalPropertyGroup.RemoveProperty ("OutputType"); - } else { - globalPropertyGroup.RemovePropertyIfHasDefaultValue ("OutputType", outputType); - } - } - - void RemoveMSBuildProjectNameDerivedProperties (MSBuildPropertyGroup globalPropertyGroup) - { - string msbuildProjectName = globalPropertyGroup.ParentProject.FileName.FileNameWithoutExtension; - - if (!hasAssemblyName) - globalPropertyGroup.RemovePropertyIfHasDefaultValue ("AssemblyName", msbuildProjectName); - - if (!hasRootNamespace) - globalPropertyGroup.RemovePropertyIfHasDefaultValue ("RootNamespace", msbuildProjectName); - } - - void UpdateTargetFramework (MSBuildProject project, TargetFrameworkMoniker framework) - { - if (targetFrameworkMoniker == framework) - return; - - string shortFrameworkName = null; - DotNetCoreShortTargetFramework shortFramework = null; - - string existingFramework = targetFrameworks.FirstOrDefault (); - bool identifiersMatch = targetFrameworkMoniker.Identifier == framework.Identifier; - - if (identifiersMatch && DotNetCoreShortTargetFramework.TryParse (existingFramework, out shortFramework)) { - shortFramework.Update (framework); - shortFrameworkName = shortFramework.ToString (); - } else { - shortFrameworkName = framework.GetShortFrameworkName (); - } - - if (existingFramework == shortFrameworkName) - return; - - if (targetFrameworks.Count == 0) - targetFrameworks.Add (shortFrameworkName); - else - targetFrameworks[0] = shortFrameworkName; - - targetFrameworkMoniker = framework; - project.UpdateTargetFrameworks (targetFrameworks); - } - - public void AddKnownItemAttributes (MSBuildProject project) - { - if (HasSdk) - ProjectPackageReference.AddKnownItemAttributes (project); - } - - 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/DotNetCoreProjectBuilderMaintainer.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectBuilderMaintainer.cs deleted file mode 100644 index 6d2e63c70d..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectBuilderMaintainer.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -// DotNetCoreProjectBuilderMaintainer.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Collections.Generic; -using MonoDevelop.PackageManagement; -using MonoDevelop.Projects; -using System.Linq; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreProjectBuilderMaintainer - { - /// <summary> - /// If the target framework of the project has changed then non .NET Core projects - /// that reference this project may need their project builders refreshed so - /// that the correct build result occurs. If the new framework is incompatible - /// then without the project builder refresh then the build error will not appear - /// until the solution is reloaded. - /// </summary> - public static void OnProjectReload (ProjectReloadedEventArgs reloadEventArgs) - { - var reloadedProject = reloadEventArgs.NewProject.DotNetProject; - foreach (var project in GetAllNonDotNetCoreProjectsReferencingProject (reloadedProject)) { - project.ReloadProjectBuilder (); - } - } - - static IEnumerable<DotNetProject> GetAllNonDotNetCoreProjects (Solution parentSolution) - { - return parentSolution.GetAllDotNetProjects () - .Where (project => !project.HasFlavor<DotNetCoreProjectExtension> ()); - } - - static IEnumerable<DotNetProject> GetAllNonDotNetCoreProjectsReferencingProject (DotNetProject dotNetCoreProject) - { - foreach (DotNetProject project in GetAllNonDotNetCoreProjects (dotNetCoreProject.ParentSolution)) { - foreach (ProjectReference projectReference in project.References) { - if (projectReference.IsProjectReference ()) { - Project resolvedProject = projectReference.ResolveProject (project.ParentSolution); - if (resolvedProject == dotNetCoreProject) { - yield return project; - } - } - } - } - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs index 5d29e5b033..a5523909a6 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs @@ -25,7 +25,6 @@ // THE SOFTWARE. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -37,22 +36,24 @@ using MonoDevelop.PackageManagement.Commands; using MonoDevelop.Projects; using MonoDevelop.Projects.MSBuild; using MonoDevelop.Ide; -using System.Collections.Immutable; namespace MonoDevelop.DotNetCore { [ExportProjectModelExtension] - public class DotNetCoreProjectExtension: DotNetProjectExtension + public class DotNetCoreProjectExtension: SdkProjectExtension { const string ShownDotNetCoreSdkInstalledExtendedPropertyName = "DotNetCore.ShownDotNetCoreSdkNotInstalledDialog"; const string GlobalJsonPathExtendedPropertyName = "DotNetCore.GlobalJsonPath"; - DotNetCoreMSBuildProject dotNetCoreMSBuildProject = new DotNetCoreMSBuildProject (); DotNetCoreSdkPaths sdkPaths; public DotNetCoreProjectExtension () { - DotNetCoreProjectReloadMonitor.Initialize (); + try { + DotNetCoreSdk.EnsureInitialized (); + } catch (Exception ex) { + LoggingService.LogInternalError ("DotNetCoreProjectExtension sdk initialization failed", ex); + } } void FileService_FileChanged (object sender, FileEventArgs e) @@ -70,30 +71,30 @@ namespace MonoDevelop.DotNetCore protected override bool SupportsObject (WorkspaceObject item) { - return DotNetCoreSupportsObject(item) && !IsWebProject ((DotNetProject)item); + return DotNetCoreSupportsObject (item) && !IsWebProject ((DotNetProject)item); } protected bool DotNetCoreSupportsObject (WorkspaceObject item) { - return base.SupportsObject (item) && IsSdkProject ((DotNetProject)item); + return base.SupportsObject (item) && HasSupportedFramework ((DotNetProject)item); } - protected override bool OnGetSupportsFramework (TargetFramework framework) + /// <summary> + /// Cannot check TargetFramework property since it may not be set. + /// Currently support .NET Core and .NET Standard. + /// </summary> + bool HasSupportedFramework (DotNetProject project) { - // Allow all SDK style projects to be loaded even if the framework is unknown. - // A PackageReference may define the target framework with an imported MSBuild file. - return true; + string framework = project.MSBuildProject.EvaluatedProperties.GetValue ("TargetFrameworkIdentifier"); + if (framework != null) + return framework == ".NETCoreApp" || framework == ".NETStandard"; + + return false; } - /// <summary> - /// Currently this project extension is enabled for all SDK style projects and - /// not just for .NET Core and .NET Standard projects. SDK project support - /// should be separated out from this extension so it can be enabled only for - /// .NET Core and .NET Standard projects. - /// </summary> - bool IsSdkProject (DotNetProject project) + protected override bool OnGetSupportsFramework (TargetFramework framework) { - return project.MSBuildProject.GetReferencedSDKs ().Length > 0; + return framework.IsNetCoreApp () || framework.IsNetStandard (); } protected override bool OnGetCanReferenceProject (DotNetProject targetProject, out string reason) @@ -118,38 +119,6 @@ namespace MonoDevelop.DotNetCore return DotNetCoreFrameworkCompatibility.CanReferenceNetStandardProject (Project.TargetFramework.Id, targetProject); } - protected override void OnReadProjectHeader (ProgressMonitor monitor, MSBuildProject msproject) - { - // Do not read the project header when re-evaluating to prevent the - // ToolsVersion that was initially read from the project being changed. - if (!Project.IsReevaluating) - dotNetCoreMSBuildProject.ReadProjectHeader (msproject); - base.OnReadProjectHeader (monitor, msproject); - } - - protected override void OnReadProject (ProgressMonitor monitor, MSBuildProject msproject) - { - dotNetCoreMSBuildProject.AddKnownItemAttributes (Project.MSBuildProject); - - base.OnReadProject (monitor, msproject); - - dotNetCoreMSBuildProject.ReadProject (msproject, Project.TargetFramework.Id); - - if (!dotNetCoreMSBuildProject.IsOutputTypeDefined) - Project.CompileTarget = dotNetCoreMSBuildProject.DefaultCompileTarget; - - Project.UseAdvancedGlobSupport = true; - Project.UseDefaultMetadataForExcludedExpandedItems = true; - Project.UseFileWatcher = true; - } - - protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject) - { - base.OnWriteProject (monitor, msproject); - - dotNetCoreMSBuildProject.WriteProject (msproject, Project.TargetFramework.Id); - } - protected override ExecutionCommand OnCreateExecutionCommand (ConfigurationSelector configSel, DotNetProjectConfiguration configuration, ProjectRunConfiguration runConfiguration) { if (Project.TargetFramework.IsNetCoreApp ()) { @@ -183,7 +152,7 @@ namespace MonoDevelop.DotNetCore FilePath GetOutputDirectory (DotNetProjectConfiguration configuration) { - string targetFramework = dotNetCoreMSBuildProject.TargetFrameworks.FirstOrDefault (); + string targetFramework = TargetFrameworks.FirstOrDefault (); FilePath outputDirectory = configuration.OutputDirectory; if (outputDirectory.IsAbsolute) @@ -206,7 +175,6 @@ namespace MonoDevelop.DotNetCore protected FilePath GetOutputFileName (DotNetProjectConfiguration configuration) { FilePath outputDirectory = GetOutputDirectory (configuration); - string assemblyName = Project.Name; return outputDirectory.Combine (configuration.OutputAssembly + ".dll"); } @@ -287,26 +255,11 @@ namespace MonoDevelop.DotNetCore } } - /// <summary> - /// Cannot use SolutionItemExtension.OnModified. It does not seem to be called. - /// </summary> - protected void OnProjectModified (object sender, SolutionItemModifiedEventArgs args) - { - if (Project.Loading) - return; - - var fileNameChange = args.LastOrDefault (arg => arg.Hint == "FileName"); - if (fileNameChange != null) { - DotNetCoreProjectFileRenamedHandler.OnProjectFileRenamed (Project); - } - } - protected override void OnItemReady () { base.OnItemReady (); - Project.Modified += OnProjectModified; FileService.FileChanged += FileService_FileChanged; - + if (!IdeApp.IsInitialized) return; @@ -359,7 +312,6 @@ namespace MonoDevelop.DotNetCore public override void Dispose () { - Project.Modified -= OnProjectModified; FileService.FileChanged -= FileService_FileChanged; if (IdeApp.IsInitialized) @@ -404,10 +356,6 @@ namespace MonoDevelop.DotNetCore BuildResult CheckCanRunCleanOrBuild () { - if (ProjectNeedsRestore ()) { - return CreateNuGetRestoreRequiredBuildResult (); - } - if (!Project.TargetFramework.Id.IsNetStandardOrNetCoreApp ()) { return null; } @@ -418,21 +366,6 @@ namespace MonoDevelop.DotNetCore return null; } - bool ProjectNeedsRestore () - { - if (Project.NuGetAssetsFileExists () && - (HasSdk || Project.DotNetCoreNuGetMSBuildFilesExist ())) { - return false; - } - - return true; - } - - BuildResult CreateNuGetRestoreRequiredBuildResult () - { - return CreateBuildError (GettextCatalog.GetString ("NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building. The NuGet MSBuild targets are generated when the NuGet packages are restored.")); - } - BuildResult CreateBuildError (string message) { var result = new BuildResult (); @@ -469,11 +402,6 @@ namespace MonoDevelop.DotNetCore return $"{message} {downloadUrl}"; } - protected override void OnBeginLoad () - { - base.OnBeginLoad (); - } - public bool HasSdk => Project.MSBuildProject.GetReferencedSDKs ().Length > 0; protected bool IsWebProject (DotNetProject project) @@ -494,103 +422,6 @@ namespace MonoDevelop.DotNetCore var referencedSdks = project.GetReferencedSDKs (); sdkPaths = DotNetCoreSdk.FindSdkPaths (referencedSdks); - dotNetCoreMSBuildProject.HasSdk = referencedSdks.Length > 0; - } - protected override async Task<ImmutableArray<ProjectFile>> OnGetSourceFiles (ProgressMonitor monitor, ConfigurationSelector configuration) - { - var sourceFiles = await base.OnGetSourceFiles (monitor, configuration); - - return AddMissingProjectFiles (sourceFiles, configuration); - } - - ImmutableArray<ProjectFile> AddMissingProjectFiles (ImmutableArray<ProjectFile> files, ConfigurationSelector configuration) - { - ImmutableArray<ProjectFile>.Builder missingFiles = null; - foreach (ProjectFile existingFile in Project.Files.Where (file => file.BuildAction == BuildAction.Compile)) { - if (!files.Any (file => file.FilePath == existingFile.FilePath)) { - if (missingFiles == null) - missingFiles = ImmutableArray.CreateBuilder<ProjectFile> (); - missingFiles.Add (existingFile); - } - } - - // Ensure generated assembly info file is available to type system. It is created in the obj - // directory and is excluded from the project with a wildcard exclude but the type system needs it to - // ensure the project's assembly information is correct to prevent diagnostic errors. - var generatedAssemblyInfoFile = GetGeneratedAssemblyInfoFile (configuration); - if (generatedAssemblyInfoFile != null) { - if (missingFiles == null) - missingFiles = ImmutableArray.CreateBuilder<ProjectFile> (); - missingFiles.Add (generatedAssemblyInfoFile); - } - - if (missingFiles == null) - return files; - - missingFiles.Capacity = missingFiles.Count + files.Length; - missingFiles.AddRange (files); - return missingFiles.MoveToImmutable (); - } - - ProjectFile GetGeneratedAssemblyInfoFile (ConfigurationSelector configuration) - { - var projectConfig = configuration.GetConfiguration (Project) as ProjectConfiguration; - if (projectConfig == null) - return null; - - bool generateAssemblyInfo = projectConfig.Properties.GetValue ("GenerateAssemblyInfo", true); - FilePath assemblyInfoFile = projectConfig.Properties.GetPathValue ("GeneratedAssemblyInfoFile"); - - if (generateAssemblyInfo && assemblyInfoFile.IsNotNull) - return new ProjectFile (assemblyInfoFile, BuildAction.Compile); - return null; - } - - protected override void OnSetFormat (MSBuildFileFormat format) - { - // Do not call base class since the solution's FileFormat will be used which is - // VS 2012 and this will set the ToolsVersion to "4.0" which we are preventing. - // Setting the ToolsVersion to "4.0" can cause the MSBuild tasks such as - // ResolveAssemblyReferences to fail for .NET Core projects when the project - // xml is generated in memory for the project builder at the same time as the - // project file is being saved. - } - - /// <summary> - /// Shared projects can trigger a reference change during re-evaluation so do not - /// restore if the project is being re-evaluated. Otherwise this could cause the - /// restore to be run repeatedly. - /// </summary> - protected override void OnReferenceAddedToProject (ProjectReferenceEventArgs e) - { - base.OnReferenceAddedToProject (e); - - if (!IsLoadingOrReevaluating ()) - RestoreNuGetPackages (); - } - - /// <summary> - /// Shared projects can trigger a reference change during re-evaluation so do not - /// restore if the project is being re-evaluated. Otherwise this could cause the - /// restore to be run repeatedly. - /// </summary> - protected override void OnReferenceRemovedFromProject (ProjectReferenceEventArgs e) - { - base.OnReferenceRemovedFromProject (e); - - if (!IsLoadingOrReevaluating ()) - RestoreNuGetPackages (); - } - - bool IsLoadingOrReevaluating () - { - return Project.Loading || Project.IsReevaluating; - } - - void RestoreNuGetPackages () - { - Runtime.AssertMainThread (); - RestorePackagesInProjectHandler.Run (Project); } public bool IsDotNetCoreSdkInstalled () @@ -607,186 +438,9 @@ namespace MonoDevelop.DotNetCore return false; } - bool IsFSharpSdkProject () - { - if (HasSdk) { - var sdks = Project.MSBuildProject.GetReferencedSDKs (); - for (var i = 0; i < sdks.Length; i++) { - if (sdks [i].Contains ("FSharp")) - return true; - } - } - return false; - } - - /// <summary> - /// Handle a new project being created and added to a new solution. In this case - /// the NuGet packages should be restored. Need to avoid running a restore when - /// a solution is being opened so check that project's parent solution is open in - /// the IDE. - /// </summary> - protected override void OnBoundToSolution () - { - base.OnBoundToSolution (); - - if (Project.Loading) - return; - - if (!IdeApp.IsInitialized) - return; - - if (IdeApp.ProjectOperations.CurrentSelectedSolution != Project.ParentSolution) - return; - - if (ProjectNeedsRestore ()) - RestorePackagesInProjectHandler.Run (Project); - } - - protected override bool OnGetSupportsImportedItem (IMSBuildItemEvaluated buildItem) - { - if (!BuildAction.DotNetActions.Contains (buildItem.Name)) - return false; - - if (IsFSharpSdkProject ()) { - // Ignore imported F# files. F# files are defined in the main project. - // This prevents duplicate F# files when a new project is first created. - if (buildItem.Include.EndsWith (".fs", StringComparison.OrdinalIgnoreCase)) - return false; - } - - if (IsFromSharedProject (buildItem)) - return false; - - // HACK: Remove any imported items that are not in the EvaluatedItems - // This may happen if a condition excludes the item. All items passed to the - // OnGetSupportsImportedItem are from the EvaluatedItemsIgnoringCondition - return Project.MSBuildProject.EvaluatedItems - .Any (item => item.IsImported && item.Name == buildItem.Name && item.Include == buildItem.Include); - } - - /// <summary> - /// Checks that the project has the HasSharedItems property set to true and the SharedGUID - /// property in its global property group. Otherwise it is not considered to be a shared project. - /// </summary> - bool IsFromSharedProject (IMSBuildItemEvaluated buildItem) - { - var globalGroup = buildItem?.SourceItem?.ParentProject?.GetGlobalPropertyGroup (); - return globalGroup?.GetValue<bool> ("HasSharedItems") == true && - globalGroup?.HasProperty ("SharedGUID") == true; - } - protected override ProjectRunConfiguration OnCreateRunConfiguration (string name) { return new DotNetCoreRunConfiguration (name, IsWeb); } - - /// <summary> - /// HACK: Hide certain files that are currently being added to the Solution window. - /// </summary> - protected override void OnItemsAdded (IEnumerable<ProjectItem> objs) - { - if (Project.Loading) { - UpdateHiddenFiles (objs.OfType<ProjectFile> ()); - } - base.OnItemsAdded (objs); - } - - void UpdateHiddenFiles (IEnumerable<ProjectFile> files) - { - foreach (var file in files) { - if (file.FilePath.ShouldBeHidden ()) - file.Flags = ProjectItemFlags.Hidden; - } - } - - protected override async Task OnReevaluateProject (ProgressMonitor monitor) - { - await base.OnReevaluateProject (monitor); - UpdateHiddenFiles (Project.Files); - } - - /// <summary> - /// Returns all transitive references. - /// </summary> - protected override async Task<List<AssemblyReference>> OnGetReferences ( - ConfigurationSelector configuration, - System.Threading.CancellationToken token) - { - var references = new List<AssemblyReference> (); - - var traversedProjects = new HashSet<string> (); - traversedProjects.Add (Project.ItemId); - - await GetTransitiveAssemblyReferences (traversedProjects, references, configuration, true, token); - - return references; - } - - /// <summary> - /// Recursively gets all transitive project references for .NET Core projects - /// and if includeNonProjectReferences is true also returns non project - /// assembly references. - /// - /// Calling base.OnGetReferences returns the directly referenced projects and - /// also all transitive references which are not project references. - /// - /// includeNonProjectReferences should be set to false when getting the - /// assembly references for referenced projects since the assembly references - /// from OnGetReferences already contains any transitive references which are - /// not projects. - /// </summary> - async Task GetTransitiveAssemblyReferences ( - HashSet<string> traversedProjects, - List<AssemblyReference> references, - ConfigurationSelector configuration, - bool includeNonProjectReferences, - System.Threading.CancellationToken token) - { - foreach (var reference in await base.OnGetReferences (configuration, token)) { - if (!reference.IsProjectReference) { - if (includeNonProjectReferences) { - references.Add (reference); - } - continue; - } - - // Project references with ReferenceOutputAssembly false should be - // added but there is no need to check any further since there will not - // any transitive project references. - if (!reference.ReferenceOutputAssembly) { - references.Add (reference); - continue; - } - - var project = reference.GetReferencedItem (Project.ParentSolution) as DotNetProject; - if (project == null) - continue; - - if (traversedProjects.Contains (project.ItemId)) - continue; - - references.Add (reference); - traversedProjects.Add (project.ItemId); - - var extension = project.AsFlavor<DotNetCoreProjectExtension> (); - if (extension != null) - await extension.GetTransitiveAssemblyReferences (traversedProjects, references, configuration, false, token); - } - } - - /// <summary> - /// ASP.NET Core projects have different build actions if the file is in the wwwroot folder. - /// It also uses Content build actions for *.json, *.config and *.cshtml files. To support - /// this the default file globs for the file are found and the MSBuild item name is returned. - /// </summary> - protected override string OnGetDefaultBuildAction (string fileName) - { - string include = MSBuildProjectService.ToMSBuildPath (Project.ItemDirectory, fileName); - var globItems = Project.MSBuildProject.FindGlobItemsIncludingFile (include).ToList (); - if (globItems.Count == 1) - return globItems [0].Name; - - return base.OnGetDefaultBuildAction (fileName); - } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectFileRenamedHandler.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectFileRenamedHandler.cs deleted file mode 100644 index 526274188a..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectFileRenamedHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// DotNetCoreProjectFileRenamedHandler.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using MonoDevelop.Projects; -using MonoDevelop.PackageManagement; -using MonoDevelop.PackageManagement.Commands; - -namespace MonoDevelop.DotNetCore -{ - static class DotNetCoreProjectFileRenamedHandler - { - public static void OnProjectFileRenamed (DotNetProject project) - { - if (!PackageManagementServices.Options.IsAutomaticPackageRestoreOnOpeningSolutionEnabled) - return; - - RestorePackagesHandler.RestoreBuildIntegratedNuGetProjects (project.ParentSolution); - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs deleted file mode 100644 index b8ef91ce9d..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReader.cs +++ /dev/null @@ -1,112 +0,0 @@ -// -// DotNetCoreProjectReader.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.IO; -using System.Threading.Tasks; -using System.Xml; -using MonoDevelop.Core; -using MonoDevelop.Projects; -using MonoDevelop.Projects.MSBuild; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreProjectReader : WorkspaceObjectReader - { - public override bool CanRead (FilePath file, Type expectedType) - { - if (!expectedType.IsAssignableFrom (typeof(SolutionItem))) - return false; - - if (file.HasSupportedDotNetCoreProjectFileExtension ()) - return IsDotNetCoreProjectFile (file); - - return false; - } - - /// <summary> - /// Check the Project element contains an Sdk and ToolsVersion attribute. - /// </summary> - static bool IsDotNetCoreProjectFile (FilePath file) - { - return GetDotNetCoreSdk (file) != null; - } - - /// <summary> - /// Returns the first Sdk property defined by the project, if any exists - /// </summary> - public static string GetDotNetCoreSdk (FilePath file) - { - try { - // A .NET Core project can define an sdk in any of the following ways - // 1) An Sdk attribute on the Project node - // 2) An Sdk node as a child of the Project node - // 3) An Sdk attribute on any Import node - var document = new XmlDocument (); - document.Load (new StreamReader (file)); - XmlNode projectNode = document.SelectSingleNode ("/Project"); - if (projectNode != null) { - XmlAttribute sdkAttr = projectNode.Attributes ["Sdk"]; - if (sdkAttr != null) { - // Found an Sdk definition on the root Project node - return sdkAttr.Value;
- } - - var childSdkNode = projectNode.SelectSingleNode ("Sdk"); - if (childSdkNode != null) { - var name = childSdkNode.Attributes ["Name"]; - if (name != null) { - // Found an Sdk definition on an Sdk node - return name.Value; - } - } - - foreach (XmlNode importNode in projectNode.SelectNodes ("//Import")) { - sdkAttr = importNode.Attributes ["Sdk"]; - if (sdkAttr != null) { - return sdkAttr.Value; - } - } - } - } catch { - // Ignore - } - return null; - } - - public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) - { - return Task.Run (() => { - if (CanRead (fileName, typeof(SolutionItem))) { - DotNetCoreSdk.EnsureInitialized (); - return MSBuildProjectService.LoadItem (monitor, fileName, MSBuildFileFormat.VS2012, typeGuid, itemGuid, ctx); - } - - throw new NotSupportedException (); - }); - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReloadMonitor.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReloadMonitor.cs deleted file mode 100644 index 637d0a6f84..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectReloadMonitor.cs +++ /dev/null @@ -1,162 +0,0 @@ -// -// DotNetCoreProjectReloadMonitor.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// 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 System.Threading.Tasks; -using MonoDevelop.Core; -using MonoDevelop.Ide; -using MonoDevelop.PackageManagement; -using MonoDevelop.PackageManagement.Commands; -using MonoDevelop.Projects; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreProjectReloadMonitor - { - static readonly DotNetCoreProjectReloadMonitor monitor = new DotNetCoreProjectReloadMonitor (); - - DotNetCoreProjectReloadMonitor () - { - if (IdeApp.IsInitialized) { - PackageManagementServices.ProjectService.ProjectReloaded += ProjectReloaded; - FileService.FileChanged += FileChanged; - } - } - - public static void Initialize () - { - } - - void ProjectReloaded (object sender, ProjectReloadedEventArgs e) - { - Runtime.AssertMainThread (); - try { - if (IsDotNetCoreProjectReloaded (e.NewProject)) { - OnDotNetCoreProjectReloaded (e); - } - } catch (Exception ex) { - LoggingService.LogError ("DotNetCoreProjectReloadMonitor error", ex); - } - } - - bool IsDotNetCoreProjectReloaded (IDotNetProject project) - { - // Ignore reloads when NuGet package restore is running. - if (PackageManagementServices.BackgroundPackageActionRunner.IsRunning) - return false; - - return project.DotNetProject.HasFlavor<DotNetCoreProjectExtension> (); - } - - void OnDotNetCoreProjectReloaded (ProjectReloadedEventArgs e) - { - DotNetCoreProjectBuilderMaintainer.OnProjectReload (e); - RestorePackagesInProjectHandler.Run (e.NewProject.DotNetProject, restoreTransitiveProjectReferences: true); - } - - async void FileChanged (object sender, FileEventArgs e) - { - Runtime.AssertMainThread (); - - try { - if (!PackageManagementServices.BackgroundPackageActionRunner.IsRunning) { - await OnFileChanged (e); - } - } catch (Exception ex) { - LoggingService.LogError ("DotNetCoreProjectReloadMonitor error", ex); - } - } - - async Task OnFileChanged (IEnumerable<FileEventInfo> files) - { - var projectFiles = GetProjectFiles (files); - if (!projectFiles.Any ()) - return; - - var unknownProjects = GetUnknownProjects (); - if (!unknownProjects.Any ()) - return; - - var projectsToReload = GetProjectsToReload (unknownProjects, projectFiles); - if (!projectsToReload.Any ()) - return; - - var reloadedProjects = await ReloadProjects (projectsToReload); - - if (reloadedProjects.Any ()) { - RestorePackages (reloadedProjects); - } - } - - IEnumerable<FileEventInfo> GetProjectFiles (IEnumerable<FileEventInfo> files) - { - return files.Where (file => file.FileName.HasSupportedDotNetCoreProjectFileExtension ()) - .ToList (); - } - - /// <summary> - /// Gets all unknown projects that are not deliberately unloaded. - /// Deliberately unloaded projects have Enabled set to false. - /// </summary> - IEnumerable<UnknownSolutionItem> GetUnknownProjects () - { - return IdeApp.Workspace.GetAllItems<UnknownSolutionItem> () - .Where (project => project.Enabled) - .ToList (); - } - - IEnumerable<UnknownSolutionItem> GetProjectsToReload ( - IEnumerable<UnknownSolutionItem> unknownProjects, - IEnumerable<FileEventInfo> projectFiles) - { - var projectFileNames = projectFiles.Select (projectFile => projectFile.FileName).ToList (); - return unknownProjects.Where (project => projectFileNames.Contains (project.FileName)).ToList (); - } - - async Task<IEnumerable<DotNetProject>> ReloadProjects (IEnumerable<UnknownSolutionItem> projectsToReload) - { - var reloadedProjects = new List<DotNetProject> (); - using (ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetProjectLoadProgressMonitor (true)) { - foreach (var project in projectsToReload) { - var reloadedProject = (await project.ParentFolder.ReloadItem (monitor, project)) as DotNetProject; - if (reloadedProject != null && reloadedProject.HasFlavor<DotNetCoreProjectExtension> ()) { - reloadedProjects.Add (reloadedProject); - } - } - } - return reloadedProjects; - } - - void RestorePackages (IEnumerable<DotNetProject> projects) - { - var actions = projects.Select (project => new RestoreNuGetPackagesInDotNetCoreProject (project)).ToList (); - var message = ProgressMonitorStatusMessageFactory.CreateRestoringPackagesInProjectMessage (); - PackageManagementServices.BackgroundPackageActionRunner.Run (message, actions); - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreShortTargetFramework.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreShortTargetFramework.cs deleted file mode 100644 index 6e982ab1f7..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreShortTargetFramework.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -// DotNetCoreShortTargetFramework.cs -// -// Author: -// Matt Ward <matt.ward@microsoft.com> -// -// Copyright (c) 2018 Microsoft -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; -using MonoDevelop.Core.Assemblies; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreShortTargetFramework - { - DotNetCoreShortTargetFramework () - { - } - - public string Identifier { get; private set; } - public string Version { get; private set; } - public string OriginalString { get; private set; } - - public override string ToString () - { - return $"{Identifier}{Version}"; - } - - /// <summary> - /// Parse the specified short target framework. Logic is based on: - /// https://github.com/dotnet/sdk/blob/cfe8ff3c4e51c473ae75ca32d1c7a62043e96990/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets#L50 - /// </summary> - public static DotNetCoreShortTargetFramework Parse (string input) - { - if (string.IsNullOrEmpty (input)) - throw new ArgumentException (".NET Core short target framework cannot be null or an empty string.", nameof (input)); - - if (input.Contains (",")) - throw new ArgumentException (".NET Core short target framework cannot contain ','.", nameof (input)); - - if (input.Contains ("+")) - throw new ArgumentException (".NET Core short target framework cannot contain '+'.", nameof (input)); - - string identifier = input.TrimEnd ('.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); - string version = input.Substring (identifier.Length); - - return new DotNetCoreShortTargetFramework { - Identifier = identifier, - OriginalString = input, - Version = version - }; - } - - public static bool TryParse (string input, out DotNetCoreShortTargetFramework framework) - { - framework = null; - - if (string.IsNullOrEmpty (input)) - return false; - - if (input.Contains (",") || input.Contains ("+")) - return false; - - framework = Parse (input); - - return true; - } - - public void Update (TargetFrameworkMoniker framework) - { - UpdateVersion (framework.Version); - } - - void UpdateVersion (string newVersion) - { - if (Version.Contains (".")) { - Version = newVersion; - } else { - Version = newVersion.Replace (".", string.Empty); - } - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs deleted file mode 100644 index 9c50031d57..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildProjectExtensions.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -// MSBuildProjectExtensions.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Collections.Generic; -using System.Linq; -using MonoDevelop.Projects.MSBuild; - -namespace MonoDevelop.DotNetCore -{ - static class MSBuildProjectExtensions - { - public static bool IsOutputTypeDefined (this MSBuildProject project) - { - return project.HasGlobalProperty ("OutputType"); - } - - public static bool HasGlobalProperty (this MSBuildProject project, string name) - { - var globalPropertyGroup = project.GetGlobalPropertyGroup (); - if (globalPropertyGroup != null) - return globalPropertyGroup.HasProperty (name); - - return false; - } - - public static IEnumerable<string> GetTargetFrameworks (this MSBuildProject project) - { - var properties = project.EvaluatedProperties; - if (properties != null) { - string targetFramework = properties.GetValue ("TargetFramework"); - if (targetFramework != null) { - return new [] { targetFramework }; - } - - string targetFrameworks = properties.GetValue ("TargetFrameworks"); - if (targetFrameworks != null) { - return targetFrameworks.Split (';'); - } - } - - return new string[0]; - } - - public static void UpdateTargetFrameworks (this MSBuildProject project, IEnumerable<string> targetFrameworks) - { - var globalPropertyGroup = project.GetGlobalPropertyGroup (); - if (targetFrameworks.Count () > 1) { - string value = string.Join (";", targetFrameworks); - globalPropertyGroup.SetValue ("TargetFrameworks", value); - } else { - globalPropertyGroup.SetValue ("TargetFramework", targetFrameworks.FirstOrDefault ()); - } - } - - public static bool ImportExists (this MSBuildProject project, string importedProjectFile) - { - return project.GetImport (importedProjectFile) != null; - } - - /// <summary> - /// Remove Name and Project from project references. - /// </summary> - public static void RemoveExtraProjectReferenceMetadata (this MSBuildProject project) - { - foreach (MSBuildItem item in project.GetAllItems ()) { - if (item.Name == "ProjectReference") { - item.Metadata.RemoveProperty ("Name"); - item.Metadata.RemoveProperty ("Project"); - } - } - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildPropertyGroupExtensions.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildPropertyGroupExtensions.cs deleted file mode 100644 index 8717f2d4a9..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/MSBuildPropertyGroupExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// MSBuildPropertyGroupExtensions.cs -// -// Author: -// Matt Ward <matt.ward@xamarin.com> -// -// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using MonoDevelop.Projects.MSBuild; - -namespace MonoDevelop.DotNetCore -{ - static class MSBuildPropertyGroupExtensions - { - public static void RemovePropertyIfHasDefaultValue ( - this MSBuildPropertyGroup propertyGroup, - string propertyName, - string defaultPropertyValue) - { - if (!propertyGroup.HasProperty (propertyName)) - return; - - if (propertyGroup.GetValue (propertyName) == defaultPropertyValue) { - propertyGroup.RemoveProperty (propertyName); - } - } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs index c49a937ebe..4e25698a1d 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs @@ -30,33 +30,6 @@ namespace MonoDevelop.DotNetCore { static class TargetFrameworkMonikerExtensions { - public static string GetShortFrameworkName (this TargetFrameworkMoniker framework) - { - if (framework.IsNetFramework ()) - return GetShortNetFrameworkName (framework); - - string identifier = GetShortFrameworkIdentifier (framework); - return identifier + framework.Version; - } - - public static string GetShortFrameworkIdentifier (this TargetFrameworkMoniker framework) - { - if (string.IsNullOrEmpty (framework.Identifier)) - return string.Empty; - - string shortFrameworkIdentifier = framework.Identifier; - - if (shortFrameworkIdentifier[0] == '.') - shortFrameworkIdentifier = shortFrameworkIdentifier.Substring (1); - - return shortFrameworkIdentifier.ToLower (); - } - - static string GetShortNetFrameworkName (TargetFrameworkMoniker framework) - { - return "net" + framework.Version.Replace (".", string.Empty); - } - public static bool IsNetFramework (this TargetFrameworkMoniker framework) { return framework.Identifier == ".NETFramework"; diff --git a/main/src/addins/MonoDevelop.DotNetCore/Properties/MonoDevelop.DotNetCore.addin.xml b/main/src/addins/MonoDevelop.DotNetCore/Properties/MonoDevelop.DotNetCore.addin.xml index f79b5f284f..ec5531c06f 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/Properties/MonoDevelop.DotNetCore.addin.xml +++ b/main/src/addins/MonoDevelop.DotNetCore/Properties/MonoDevelop.DotNetCore.addin.xml @@ -1159,10 +1159,6 @@ <NodeBuilder class="MonoDevelop.DotNetCore.ProjXNodeBuilderExtension" /> </Extension> - <Extension path="/MonoDevelop/ProjectModel/WorkspaceObjectReaders"> - <Class id="DotNetCoreProjectReader" class="MonoDevelop.DotNetCore.DotNetCoreProjectReader" /> - </Extension> - <ExtensionPoint path="/MonoDevelop/DotNetCore/ContextMenu/ProjectPad/PackageDependency"> <ExtensionNodeSet id="MonoDevelop.Components.Commands.ItemSet"/> </ExtensionPoint> |