diff --git a/TestAssets/ProjectModelServer/DthTestProjects/global.json b/TestAssets/ProjectModelServer/DthTestProjects/global.json deleted file mode 100644 index 364730368..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/global.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "projects": ["src"] -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectPathSample/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectPathSample/project.json deleted file mode 100644 index 6390ad290..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectPathSample/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.App": "1.0.0", - "EmptyLibrary": "1.0.0-*" - }, - "frameworks": { - "netcoreapp1.0": {} - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/Program.cs b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/Program.cs deleted file mode 100644 index 6c7859b64..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Misc.DthTestProjects.EmptyConsoleApp -{ - public class Program - { - public int Main(string[] args) - { - Console.WriteLine("Hello, world."); - return 0; - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/project.json deleted file mode 100644 index a1827ad70..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyConsoleApp/project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": {}, - "frameworks": { - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": "1.0.0" - } - }, - "dnx451": {} - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/Class.cs b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/Class.cs deleted file mode 100644 index 3fe898a95..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/Class.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace Misc.DthTestProjects.EmptyLibrary -{ - public class Class - { - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json deleted file mode 100644 index ebe3e29af..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { }, - "frameworks": { - "dnxcore50": { - "dependencies":{ - "NETStandard.Library": "1.0.0-rc2-23811", - "System.Console": "4.0.0-beta-*" - } - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json deleted file mode 100644 index 3ab07f47c..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "1.0.0-*", - "dependencies": {}, - "frameworks": { - "netstandard1.3": { - "imports": "dnxcore50", - "dependencies": { - "NETStandard.Library": "1.6.0" - } - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/Program.cs b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/Program.cs deleted file mode 100644 index 9e6dde0c3..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Misc.DthTestProjects.SimpleConsoleApp -{ - public class Program - { - public int Main(string[] args) - { - Console.WriteLine("Hello, world."); - return 0; - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/project.json deleted file mode 100644 index b20601e54..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyNetCoreApp/project.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "dependencies": {}, - "frameworks": { - "netcoreapp1.0": { - "imports": "dnxcore50", - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "Newtonsoft.Json": "8.0.3" - } - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/Program.cs b/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/Program.cs deleted file mode 100644 index e2e4aa3a1..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace FailReleaseProject -{ - public class Program - { - public int Main(string[] args) - { -#if RELEASE - // fail the compilation under Release configuration - i -#endif - return 0; - } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json deleted file mode 100644 index 6bddf49a1..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "frameworks": { - "netcoreapp1.0": { - "imports": "dnxcore50", - "dependencies": { - "Microsoft.NETCore.App": "1.0.0" - } - } - }, - "dependencies": {} -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/IncompatiblePackageSample/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/IncompatiblePackageSample/project.json deleted file mode 100644 index 6a03cc355..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/IncompatiblePackageSample/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.App": "1.0.0", - "Microsoft.Web.Administration": "7.0.0" - }, - "frameworks": { - "netcoreapp1.0": {} - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedPackageSample/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedPackageSample/project.json deleted file mode 100644 index e9ba88773..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedPackageSample/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "NoSuchPackage": "1.0.0" - }, - "frameworks": { - "dnx451": { } - } -} diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedProjectSample/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedProjectSample/project.json deleted file mode 100644 index 330ce6436..000000000 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/UnresolvedProjectSample/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "EmptyLibrary": "1.0.0-*" - }, - "frameworks": { - "dnx451": { } - } -} diff --git a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/ext/Newtonsoft.Json/project.json b/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/ext/Newtonsoft.Json/project.json deleted file mode 100644 index 49f740598..000000000 --- a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/ext/Newtonsoft.Json/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": "9.0.1", - "dependencies": { - }, - "frameworks": { - "netstandard1.5": { } - } -} diff --git a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/global.json b/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/global.json deleted file mode 100644 index c6bd139a9..000000000 --- a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ - "src", - "../ext" - ] -} diff --git a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/src/MainProject/project.json b/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/src/MainProject/project.json deleted file mode 100644 index aa50018cd..000000000 --- a/TestAssets/ProjectModelServer/DthUpdateSearchPathSample/home/src/MainProject/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "Newtonsoft.Json": "9.0.1" - }, - "frameworks": { - "netstandard1.5": {} - } -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json b/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json deleted file mode 100644 index 6663ba432..000000000 --- a/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "projects": ["src"]] -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config deleted file mode 100755 index e80222c1f..000000000 --- a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs deleted file mode 100755 index 51233cffa..000000000 --- a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace ConsoleApplication -{ - public class Program - { - public static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json deleted file mode 100755 index 71152b304..000000000 --- a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Microsoft.NETCore.App": "1.0.0" - }, - "frameworks": { - "netcoreapp1.0": {} - } -} diff --git a/TestAssets/ProjectModelServer/IncorrectProjectJson/project.json b/TestAssets/ProjectModelServer/IncorrectProjectJson/project.json deleted file mode 100644 index 891039f78..000000000 --- a/TestAssets/ProjectModelServer/IncorrectProjectJson/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": "1.0.0-*", - "dependencies": { - " - }, - "frameworks": { - [] - } -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/.gitignore b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/.gitignore deleted file mode 100644 index 497f0e325..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Negates the lock file -# MSBuiild references' project model server tests requires these lock files, since they can't be created without VS tooling. -!project.lock.json diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Class1.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Class1.cs deleted file mode 100644 index 08281c64a..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ClassLibrary1 -{ - public class Class1 - { - } -} diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/ClassLibrary1.csproj b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/ClassLibrary1.csproj deleted file mode 100644 index 7364cb64d..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/ClassLibrary1.csproj +++ /dev/null @@ -1,62 +0,0 @@ - - - - - Debug - AnyCPU - {FD073258-550B-4E57-86AE-DC4874015EB1} - Library - Properties - ClassLibrary1 - ClassLibrary1 - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Properties/AssemblyInfo.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Properties/AssemblyInfo.cs deleted file mode 100644 index 6437643a7..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary1")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ClassLibrary1")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("fd073258-550b-4e57-86ae-dc4874015eb1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/packages.config b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/packages.config deleted file mode 100644 index 1975352b1..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary1/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Class1.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Class1.cs deleted file mode 100644 index ad2fff55e..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ClassLibrary2 -{ - public class Class1 - { - } -} diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/ClassLibrary2.csproj b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/ClassLibrary2.csproj deleted file mode 100644 index fb17ee317..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/ClassLibrary2.csproj +++ /dev/null @@ -1,61 +0,0 @@ - - - - - Debug - AnyCPU - 0f2d2a48-e867-496c-85a7-e97b64cfeda4 - Library - Properties - ClassLibrary2 - ClassLibrary2 - v4.6 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Properties/AssemblyInfo.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Properties/AssemblyInfo.cs deleted file mode 100644 index b40cfab4c..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary2/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary2")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ClassLibrary2")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0f2d2a48-e867-496c-85a7-e97b64cfeda4")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Class1.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Class1.cs deleted file mode 100644 index 21384c5b2..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ClassLibrary3 -{ - public class Class1 - { - } -} diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/ClassLibrary3.csproj b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/ClassLibrary3.csproj deleted file mode 100644 index 0bcde3dfe..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/ClassLibrary3.csproj +++ /dev/null @@ -1,61 +0,0 @@ - - - - - Debug - AnyCPU - 428e95cb-8435-414b-a313-9d734c633b3e - Library - Properties - ClassLibrary3 - ClassLibrary3 - v4.6 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Properties/AssemblyInfo.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Properties/AssemblyInfo.cs deleted file mode 100644 index 0eadf724e..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ClassLibrary3/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary3")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ClassLibrary3")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("428e95cb-8435-414b-a313-9d734c633b3e")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ConsoleApp13.sln b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ConsoleApp13.sln deleted file mode 100644 index 1ac8ff099..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/ConsoleApp13.sln +++ /dev/null @@ -1,53 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25029.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1443ACE0-3065-4C20-AD59-D561798AE0A5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0AE82780-22C8-4DC8-8F1E-86977FDD092F}" - ProjectSection(SolutionItems) = preProject - global.json = global.json - EndProjectSection -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ConsoleApp13", "src\ConsoleApp13\ConsoleApp13.xproj", "{767D3038-AC3A-4722-B21F-F85F2CBC3AA3}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{FD073258-550B-4E57-86AE-DC4874015EB1}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.csproj", "{0F2D2A48-E867-496C-85A7-E97B64CFEDA4}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary3", "ClassLibrary3\ClassLibrary3.csproj", "{428E95CB-8435-414B-A313-9D734C633B3E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {767D3038-AC3A-4722-B21F-F85F2CBC3AA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {767D3038-AC3A-4722-B21F-F85F2CBC3AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {767D3038-AC3A-4722-B21F-F85F2CBC3AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {767D3038-AC3A-4722-B21F-F85F2CBC3AA3}.Release|Any CPU.Build.0 = Release|Any CPU - {FD073258-550B-4E57-86AE-DC4874015EB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FD073258-550B-4E57-86AE-DC4874015EB1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FD073258-550B-4E57-86AE-DC4874015EB1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FD073258-550B-4E57-86AE-DC4874015EB1}.Release|Any CPU.Build.0 = Release|Any CPU - {0F2D2A48-E867-496C-85A7-E97B64CFEDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0F2D2A48-E867-496C-85A7-E97B64CFEDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0F2D2A48-E867-496C-85A7-E97B64CFEDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0F2D2A48-E867-496C-85A7-E97B64CFEDA4}.Release|Any CPU.Build.0 = Release|Any CPU - {428E95CB-8435-414B-A313-9D734C633B3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {428E95CB-8435-414B-A313-9D734C633B3E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {428E95CB-8435-414B-A313-9D734C633B3E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {428E95CB-8435-414B-A313-9D734C633B3E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {767D3038-AC3A-4722-B21F-F85F2CBC3AA3} = {1443ACE0-3065-4C20-AD59-D561798AE0A5} - {FD073258-550B-4E57-86AE-DC4874015EB1} = {1443ACE0-3065-4C20-AD59-D561798AE0A5} - {0F2D2A48-E867-496C-85A7-E97B64CFEDA4} = {1443ACE0-3065-4C20-AD59-D561798AE0A5} - {428E95CB-8435-414B-A313-9D734C633B3E} = {1443ACE0-3065-4C20-AD59-D561798AE0A5} - EndGlobalSection -EndGlobal diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/global.json b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/global.json deleted file mode 100644 index 5e6422e6d..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/global.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "projects": [ "src", "test" ] -} diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/MainApp.xproj b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/MainApp.xproj deleted file mode 100644 index ec559dc46..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/MainApp.xproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 767d3038-ac3a-4722-b21f-f85f2cbc3aa3 - ConsoleApp13 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\ - v4.6 - - - 2.0 - - - - - - - - \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Program.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Program.cs deleted file mode 100644 index 6723332b1..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Program.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace ConsoleApp13 -{ - public class Program - { - public static void Main(string[] args) - { - var q = new ClassLibrary1.Class1(); - } - } -} diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Properties/AssemblyInfo.cs b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Properties/AssemblyInfo.cs deleted file mode 100644 index 83e8803f8..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ConsoleApp13")] -[assembly: AssemblyTrademark("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("767d3038-ac3a-4722-b21f-f85f2cbc3aa3")] diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.fragment.lock.json b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.fragment.lock.json deleted file mode 100644 index 1efff4670..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.fragment.lock.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": 2, - "exports": { - "ClassLibrary1/1.0.0": { - "type": "project", - "framework": ".NETFramework,Version=v4.5.2", - "compile": { - "bin/Debug/ClassLibrary1.dll": {} - }, - "runtime": { - "../packages/Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll": {}, - "bin/Debug/ClassLibrary1.dll": {} - } - }, - "ClassLibrary2/1.0.0": { - "type": "project", - "framework": ".NETFramework,Version=v4.6", - "compile": { - "bin/Debug/ClassLibrary2.dll": {} - }, - "runtime": { - "bin/Debug/ClassLibrary2.dll": {} - } - }, - "ClassLibrary3/1.0.0": { - "type": "project", - "framework": ".NETFramework,Version=v4.6", - "compile": { - "bin/Debug/ClassLibrary3.dll": {} - }, - "runtime": { - "bin/Debug/ClassLibrary3.dll": {} - } - } - } -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.json b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.json deleted file mode 100644 index 34284fa19..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true - }, - "frameworks": { - "net46": { - "dependencies": { - "ClassLibrary1": { - "target": "project" - }, - "ClassLibrary2": { - "target": "project" - }, - "ClassLibrary3": { - "target": "project" - } - } - } - } -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.lock.json b/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.lock.json deleted file mode 100644 index 244c3771b..000000000 --- a/TestAssets/ProjectModelServer/MSBuildReferencesProjects/ValidCase01/src/MainApp/project.lock.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "locked": false, - "version": 2, - "targets": { - ".NETFramework,Version=v4.6": { - "ClassLibrary1/1.0.0": { - "type": "project" - }, - "ClassLibrary2/1.0.0": { - "type": "project" - }, - "ClassLibrary3/1.0.0": { - "type": "project" - } - }, - ".NETFramework,Version=v4.6/win7-x64": { - "ClassLibrary1/1.0.0": { - "type": "project" - }, - "ClassLibrary2/1.0.0": { - "type": "project" - }, - "ClassLibrary3/1.0.0": { - "type": "project" - } - }, - ".NETFramework,Version=v4.6/win7-x86": { - "ClassLibrary1/1.0.0": { - "type": "project" - }, - "ClassLibrary2/1.0.0": { - "type": "project" - }, - "ClassLibrary3/1.0.0": { - "type": "project" - } - } - }, - "libraries": { - "ClassLibrary1/1.0.0": { - "type": "project", - "msbuildProject": "../../ClassLibrary1/ClassLibrary1.csproj" - }, - "ClassLibrary2/1.0.0": { - "type": "project", - "msbuildProject": "../../ClassLibrary2/ClassLibrary2.csproj" - }, - "ClassLibrary3/1.0.0": { - "type": "project", - "msbuildProject": "../../ClassLibrary3/ClassLibrary3.csproj" - } - }, - "projectFileDependencyGroups": { - "": [], - ".NETFramework,Version=v4.6": [ - "ClassLibrary1", - "ClassLibrary2", - "ClassLibrary3" - ] - } -} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/MscorlibLibraryDuplication/project.json b/TestAssets/ProjectModelServer/MscorlibLibraryDuplication/project.json deleted file mode 100644 index a446526e2..000000000 --- a/TestAssets/ProjectModelServer/MscorlibLibraryDuplication/project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - }, - "frameworks": { - "net45": { - "frameworkAssemblies": { - "mscorlib": "" - } - } - } -} \ No newline at end of file diff --git a/build_projects/dotnet-cli-build/TestTargets.cs b/build_projects/dotnet-cli-build/TestTargets.cs index db692a7ee..b18bee36f 100644 --- a/build_projects/dotnet-cli-build/TestTargets.cs +++ b/build_projects/dotnet-cli-build/TestTargets.cs @@ -30,8 +30,6 @@ namespace Microsoft.DotNet.Cli.Build // "dotnet-compile-fsc.Tests", "dotnet-new.Tests", "dotnet-pack.Tests", - // TODO: https://github.com/dotnet/cli/issues/3734 - //"dotnet-projectmodel-server.Tests", "dotnet-publish.Tests", "dotnet-resgen.Tests", "dotnet-run.Tests", @@ -137,19 +135,6 @@ namespace Microsoft.DotNet.Cli.Build .Execute() .EnsureSuccessful(); - // The 'ProjectModelServer' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output - dotnet.Restore( - "--verbosity", "verbose", - "--infer-runtimes") - .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer", "DthTestProjects")) - .Execute(); - - dotnet.Restore( - "--verbosity", "verbose", - "--infer-runtimes") - .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer", "DthUpdateSearchPathSample")) - .Execute(); - return c.Success(); } diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 9cabbcffc..a9508a01b 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -10,7 +10,6 @@ using System.Text; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.InternalAbstractions; -using Microsoft.DotNet.ProjectModel.Server; using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Compiler; using Microsoft.DotNet.Tools.Compiler.Csc; @@ -33,7 +32,6 @@ namespace Microsoft.DotNet.Cli ["help"] = HelpCommand.Run, ["new"] = NewCommand.Run, ["pack"] = PackCommand.Run, - ["projectmodel-server"] = ProjectModelServerCommand.Run, ["publish"] = PublishCommand.Run, ["restore"] = RestoreCommand.Run, ["run"] = RunCommand.Run, diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ConnectionContext.cs b/src/dotnet/commands/dotnet-projectmodel-server/ConnectionContext.cs deleted file mode 100644 index 235db0530..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/ConnectionContext.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using System.Net.Sockets; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ConnectionContext - { - private readonly string _hostName; - private readonly ProcessingQueue _queue; - private readonly IDictionary _projects; - - public ConnectionContext(Socket acceptedSocket, - string hostName, - ProtocolManager protocolManager, - DesignTimeWorkspace workspaceContext, - IDictionary projects) - { - _hostName = hostName; - _projects = projects; - - _queue = new ProcessingQueue(new NetworkStream(acceptedSocket)); - _queue.OnReceive += message => - { - if (protocolManager.IsProtocolNegotiation(message)) - { - message.Sender = this; - protocolManager.Negotiate(message); - } - else - { - message.Sender = this; - ProjectManager projectManager; - if (!_projects.TryGetValue(message.ContextId, out projectManager)) - { - projectManager = new ProjectManager(message.ContextId, - workspaceContext, - protocolManager); - - _projects[message.ContextId] = projectManager; - } - - projectManager.OnReceive(message); - } - }; - } - - public void QueueStart() - { - _queue.Start(); - } - - public bool Transmit(Message message) - { - message.HostId = _hostName; - return _queue.Send(message); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs deleted file mode 100644 index 7865c3126..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; - -namespace Microsoft.DotNet.ProjectModel.Server.Helpers -{ - internal class DependencyTypeChangeFinder - { - public static IEnumerable Diagnose( - ProjectContext context, - IEnumerable previousSearchPaths) - { - var result = new List(); - var project = context.ProjectFile; - var libraries = context.LibraryManager.GetLibraries(); - - var updatedSearchPath = GetUpdatedSearchPaths(previousSearchPaths, project.ResolveSearchPaths()); - var projectCandiates = GetProjectCandidates(updatedSearchPath); - var rootDependencies = libraries.FirstOrDefault(library => string.Equals(library.Identity.Name, project.Name)) - ?.Dependencies - ?.ToDictionary(libraryRange => libraryRange.Name); - - foreach (var library in libraries) - { - var diagnostic = Validate(library, projectCandiates, rootDependencies); - if (diagnostic != null) - { - result.Add(diagnostic); - } - } - - return result; - } - - private static DiagnosticMessage Validate(LibraryDescription library, - HashSet projectCandidates, - Dictionary rootDependencies) - { - if (!library.Resolved || projectCandidates == null) - { - return null; - } - - var foundCandidate = projectCandidates.Contains(library.Identity.Name); - - if ((library.Identity.Type == LibraryType.Project && !foundCandidate) || - (library.Identity.Type == LibraryType.Package && foundCandidate)) - { - library.Resolved = false; - - var libraryRange = rootDependencies[library.Identity.Name]; - - return new DiagnosticMessage( - ErrorCodes.NU1010, - $"The type of dependency {library.Identity.Name} was changed.", - libraryRange.SourceFilePath, - DiagnosticMessageSeverity.Error, - libraryRange.SourceLine, - libraryRange.SourceColumn, - library); - } - - return null; - } - - private static HashSet GetProjectCandidates(IEnumerable searchPaths) - { - if (searchPaths == null) - { - return null; - } - - return new HashSet(searchPaths.Where(path => Directory.Exists(path)) - .SelectMany(path => Directory.GetDirectories(path)) - .Where(path => File.Exists(Path.Combine(path, Project.FileName))) - .Select(path => Path.GetFileName(path))); - } - - /// - /// Returns the search paths if they're updated. Otherwise returns null. - /// - private static IEnumerable GetUpdatedSearchPaths(IEnumerable oldSearchPaths, - IEnumerable newSearchPaths) - { - // The oldSearchPaths is null when the current project is not initialized. It is not necessary to - // validate the dependency in this case. - if (oldSearchPaths == null) - { - return null; - } - - if (Enumerable.SequenceEqual(oldSearchPaths, newSearchPaths)) - { - return null; - } - - return newSearchPaths; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/JTokenExtensions.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/JTokenExtensions.cs deleted file mode 100644 index 9edd1d8bf..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/JTokenExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Newtonsoft.Json.Linq; - -namespace Microsoft.DotNet.ProjectModel.Server.Helpers -{ - public static class JTokenExtensions - { - public static string GetValue(this JToken token, string name) - { - return GetValue(token, name); - } - - public static TVal GetValue(this JToken token, string name) - { - var value = token?[name]; - if (value != null) - { - return value.Value(); - } - - return default(TVal); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs deleted file mode 100644 index 2c86daade..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.DotNet.ProjectModel.Graph; - -namespace Microsoft.DotNet.ProjectModel.Server.Helpers -{ - public static class LibraryExtensions - { - public static string GetUniqueName(this LibraryDescription library) - { - var identity = library.Identity; - return identity.Type != LibraryType.ReferenceAssembly ? identity.Name : $"fx/{identity.Name}"; - } - - public static string GetUniqueName(this LibraryRange range) - { - return range.Target != LibraryType.ReferenceAssembly ? range.Name : $"fx/{range.Name}"; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/NuGetFrameworkExtensions.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/NuGetFrameworkExtensions.cs deleted file mode 100644 index 5bc8c1d53..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/NuGetFrameworkExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.DotNet.ProjectModel.Resolution; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public static class NuGetFrameworkExtensions - { - public static FrameworkData ToPayload(this NuGetFramework framework) - { - return new FrameworkData - { - ShortName = framework.GetShortFolderName(), - FrameworkName = framework.DotNetFrameworkName, - FriendlyName = FrameworkReferenceResolver.Default.GetFriendlyFrameworkName(framework), - RedistListPath = FrameworkReferenceResolver.Default.GetFrameworkRedistListPath(framework) - }; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/ProjectExtensions.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/ProjectExtensions.cs deleted file mode 100644 index ef28bbc23..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/ProjectExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; - -namespace Microsoft.DotNet.ProjectModel.Server.Helpers -{ - public static class ProjectExtensions - { - public static IEnumerable ResolveSearchPaths(this Project project) - { - GlobalSettings settings; - return project.ResolveSearchPaths(out settings); - } - - public static IEnumerable ResolveSearchPaths(this Project project, out GlobalSettings globalSettings) - { - if (project == null) - { - throw new ArgumentNullException(nameof(project)); - } - - var searchPaths = new HashSet { Directory.GetParent(project.ProjectDirectory).FullName }; - - globalSettings = project.ResolveGlobalSettings(); - if (globalSettings != null) - { - foreach (var searchPath in globalSettings.ProjectSearchPaths) - { - var path = Path.Combine(globalSettings.DirectoryPath, searchPath); - searchPaths.Add(Path.GetFullPath(path)); - } - } - - return searchPaths; - } - - public static GlobalSettings ResolveGlobalSettings(this Project project) - { - if (project == null) - { - throw new ArgumentNullException(nameof(project)); - } - - GlobalSettings settings; - var root = ProjectRootResolver.ResolveRootDirectory(project.ProjectDirectory); - if (GlobalSettings.TryGetGlobalSettings(root, out settings)) - { - return settings; - } - else - { - return null; - } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs b/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs deleted file mode 100644 index 1307714d0..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.Cli.Compiler.Common; -using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.ProjectModel.Server.Helpers; -using Microsoft.DotNet.ProjectModel.Server.Models; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ProjectContextSnapshot - { - public string RootDependency { get; set; } - public NuGetFramework TargetFramework { get; set; } - public IReadOnlyList SourceFiles { get; set; } - public CommonCompilerOptions CompilerOptions { get; set; } - public IReadOnlyList ProjectReferences { get; set; } - public IReadOnlyList FileReferences { get; set; } - public IReadOnlyList DependencyDiagnostics { get; set; } - public IDictionary Dependencies { get; set; } - - public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable previousSearchPaths) - { - var snapshot = new ProjectContextSnapshot(); - - var allDependencyDiagnostics = new List(); - allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics()); - allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, previousSearchPaths)); - - var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source); - - var allExports = context.CreateExporter(configuration) - .GetAllExports() - .ToDictionary(export => export.Library.Identity.Name); - - var allSourceFiles = new List(GetSourceFiles(context, configuration)); - var allFileReferences = new List(); - var allProjectReferences = new List(); - var allDependencies = new Dictionary(); - - // All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export - // both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency. - foreach (var export in allExports.Values) - { - allSourceFiles.AddRange(export.SourceReferences.Select(f => f.ResolvedPath)); - var diagnostics = diagnosticsLookup[export.Library].ToList(); - var description = DependencyDescription.Create(export.Library, diagnostics, allExports); - allDependencies[description.Name] = description; - - var projectReferene = ProjectReferenceDescription.Create(export.Library); - if (projectReferene != null && export.Library.Identity.Name != context.ProjectFile.Name) - { - allProjectReferences.Add(projectReferene); - } - - if (export.Library.Identity.Type != LibraryType.Project) - { - allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath)); - } - } - - snapshot.RootDependency = context.ProjectFile.Name; - snapshot.TargetFramework = context.TargetFramework; - snapshot.SourceFiles = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList(); - snapshot.CompilerOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration); - snapshot.ProjectReferences = allProjectReferences.OrderBy(reference => reference.Name).ToList(); - snapshot.FileReferences = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList(); - snapshot.DependencyDiagnostics = allDependencyDiagnostics; - snapshot.Dependencies = allDependencies; - - return snapshot; - } - - private static IEnumerable GetSourceFiles(ProjectContext context, string configuration) - { - var compilerOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration); - - if (compilerOptions.CompileInclude == null) - { - return context.ProjectFile.Files.SourceFiles; - } - - var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.CompileInclude, "/", diagnostics: null); - - return includeFiles.Select(f => f.SourcePath); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectSnapshot.cs b/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectSnapshot.cs deleted file mode 100644 index 0b28210bf..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectSnapshot.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Helpers; -using Microsoft.DotNet.ProjectModel.Server.Models; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ProjectSnapshot - { - public Project Project { get; set; } - public string GlobalJsonPath { get; set; } - public IReadOnlyList ProjectSearchPaths { get; set; } - public IReadOnlyList ProjectDiagnostics { get; set; } - public ErrorMessage GlobalErrorMessage { get; set; } - public Dictionary ProjectContexts { get; } = new Dictionary(); - - public static ProjectSnapshot Create(string projectDirectory, - string configuration, - DesignTimeWorkspace workspaceContext, - IReadOnlyList previousSearchPaths, - bool clearWorkspaceContextCache) - { - var projectContextsCollection = workspaceContext.GetProjectContextCollection(projectDirectory, clearWorkspaceContextCache); - if (!projectContextsCollection.ProjectContexts.Any()) - { - throw new InvalidOperationException($"Unable to find project.json in '{projectDirectory}'"); - } - GlobalSettings globalSettings; - var currentSearchPaths = projectContextsCollection.Project.ResolveSearchPaths(out globalSettings); - - var snapshot = new ProjectSnapshot(); - snapshot.Project = projectContextsCollection.Project; - snapshot.ProjectDiagnostics = new List(projectContextsCollection.ProjectDiagnostics); - snapshot.ProjectSearchPaths = currentSearchPaths.ToList(); - snapshot.GlobalJsonPath = globalSettings?.FilePath; - - foreach (var projectContext in projectContextsCollection.FrameworkOnlyContexts) - { - snapshot.ProjectContexts[projectContext.TargetFramework] = - ProjectContextSnapshot.Create(projectContext, configuration, previousSearchPaths); - } - - return snapshot; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/MessageTypes.cs b/src/dotnet/commands/dotnet-projectmodel-server/MessageTypes.cs deleted file mode 100644 index df9419502..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/MessageTypes.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.DotNet.ProjectModel.Server -{ - public class MessageTypes - { - // Incoming - public const string Initialize = nameof(Initialize); - public const string ChangeConfiguration = nameof(ChangeConfiguration); - public const string RefreshDependencies = nameof(RefreshDependencies); - public const string RestoreComplete = nameof(RestoreComplete); - public const string FilesChanged = nameof(FilesChanged); - public const string GetDiagnostics = nameof(GetDiagnostics); - public const string ProtocolVersion = nameof(ProtocolVersion); - - // Outgoing - public const string Error = nameof(Error); - public const string ProjectInformation = nameof(ProjectInformation); - public const string Diagnostics = nameof(Diagnostics); - public const string DependencyDiagnostics = nameof(DependencyDiagnostics); - public const string Dependencies = nameof(Dependencies); - public const string CompilerOptions = nameof(CompilerOptions); - public const string References = nameof(References); - public const string Sources = nameof(Sources); - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/CompilerOptionsMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/CompilerOptionsMessenger.cs deleted file mode 100644 index 57c46426b..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/CompilerOptionsMessenger.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class CompilerOptionsMessenger : Messenger - { - public CompilerOptionsMessenger(Action transmit) - : base(MessageTypes.CompilerOptions, transmit) - { } - - protected override bool CheckDifference(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - return remote.CompilerOptions != null && - Equals(local.CompilerOptions, remote.CompilerOptions); - } - - protected override void SendPayload(ProjectContextSnapshot local, Action send) - { - send(new CompilationOptionsMessage - { - Framework = local.TargetFramework.ToPayload(), - Options = local.CompilerOptions - }); - } - - protected override void SetValue(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - remote.CompilerOptions = local.CompilerOptions; - } - - private class CompilationOptionsMessage - { - public FrameworkData Framework { get; set; } - - public CommonCompilerOptions Options { get; set; } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependenciesMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependenciesMessenger.cs deleted file mode 100644 index e89fcabc4..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependenciesMessenger.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class DependenciesMessenger : Messenger - { - public DependenciesMessenger(Action transmit) - : base(MessageTypes.Dependencies, transmit) - { } - - protected override bool CheckDifference(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - return remote.Dependencies != null && - string.Equals(local.RootDependency, remote.RootDependency) && - Equals(local.TargetFramework, remote.TargetFramework) && - Enumerable.SequenceEqual(local.Dependencies, remote.Dependencies); - } - - protected override void SendPayload(ProjectContextSnapshot local, Action send) - { - send(new DependenciesMessage - { - Framework = local.TargetFramework.ToPayload(), - RootDependency = local.RootDependency, - Dependencies = local.Dependencies - }); - } - - protected override void SetValue(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - remote.Dependencies = local.Dependencies; - } - - private class DependenciesMessage - { - public FrameworkData Framework { get; set; } - public string RootDependency { get; set; } - public IDictionary Dependencies { get; set; } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependencyDiagnosticsMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependencyDiagnosticsMessenger.cs deleted file mode 100644 index fa95b756b..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/DependencyDiagnosticsMessenger.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class DependencyDiagnosticsMessenger : Messenger - { - public DependencyDiagnosticsMessenger(Action transmit) - : base(MessageTypes.DependencyDiagnostics, transmit) - { } - - protected override bool CheckDifference(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - return remote.DependencyDiagnostics != null && - Enumerable.SequenceEqual(local.DependencyDiagnostics, remote.DependencyDiagnostics); - } - - protected override void SendPayload(ProjectContextSnapshot local, Action send) - { - send(new DiagnosticsListMessage( - local.DependencyDiagnostics, - local.TargetFramework?.ToPayload())); - } - - protected override void SetValue(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - remote.DependencyDiagnostics = local.DependencyDiagnostics; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/GlobalErrorMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/GlobalErrorMessenger.cs deleted file mode 100644 index 854465ef8..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/GlobalErrorMessenger.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class GlobalErrorMessenger : Messenger - { - public GlobalErrorMessenger(Action transmit) - : base(MessageTypes.Error, transmit) - { } - - protected override bool CheckDifference(ProjectSnapshot local, ProjectSnapshot remote) - { - return remote != null && Equals(local.GlobalErrorMessage, remote.GlobalErrorMessage); - } - - protected override void SendPayload(ProjectSnapshot local, Action send) - { - if (local.GlobalErrorMessage != null) - { - send(local.GlobalErrorMessage); - } - else - { - send(new ErrorMessage - { - Message = null, - Path = null, - Line = -1, - Column = -1 - }); - } - } - - protected override void SetValue(ProjectSnapshot local, ProjectSnapshot remote) - { - remote.GlobalErrorMessage = local.GlobalErrorMessage; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/Messenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/Messenger.cs deleted file mode 100644 index 5805e9425..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/Messenger.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal abstract class Messenger where T : class - { - protected readonly Action _transmit; - - public Messenger(string messageType, Action transmit) - { - _transmit = transmit; - - MessageType = messageType; - } - - public string MessageType { get; } - - public void UpdateRemote(T local, T remote) - { - if (!CheckDifference(local, remote)) - { - SendPayload(local, payload => _transmit(MessageType, payload)); - SetValue(local, remote); - } - } - - protected abstract void SetValue(T local, T remote); - protected abstract void SendPayload(T local, Action send); - protected abstract bool CheckDifference(T local, T remote); - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectDiagnosticsMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectDiagnosticsMessenger.cs deleted file mode 100644 index 4ef95660d..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectDiagnosticsMessenger.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class ProjectDiagnosticsMessenger : Messenger - { - public ProjectDiagnosticsMessenger(Action transmit) - : base(MessageTypes.Diagnostics, transmit) - { } - - protected override bool CheckDifference(ProjectSnapshot local, ProjectSnapshot remote) - { - return remote.ProjectDiagnostics != null && - Enumerable.SequenceEqual(local.ProjectDiagnostics, remote.ProjectDiagnostics); - } - - protected override void SendPayload(ProjectSnapshot local, Action send) - { - send(new DiagnosticsListMessage(local.ProjectDiagnostics)); - } - - protected override void SetValue(ProjectSnapshot local, ProjectSnapshot remote) - { - remote.ProjectDiagnostics = local.ProjectDiagnostics; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectInformationMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectInformationMessenger.cs deleted file mode 100644 index 096f42747..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ProjectInformationMessenger.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class ProjectInformationMessenger : Messenger - { - public ProjectInformationMessenger(Action transmit) - : base(MessageTypes.ProjectInformation, transmit) - { } - - protected override bool CheckDifference(ProjectSnapshot local, ProjectSnapshot remote) - { - return remote.Project != null && - string.Equals(local.Project.Name, remote.Project.Name) && - string.Equals(local.GlobalJsonPath, remote.GlobalJsonPath) && - Enumerable.SequenceEqual(local.Project.GetTargetFrameworks().Select(f => f.FrameworkName), - remote.Project.GetTargetFrameworks().Select(f => f.FrameworkName)) && - Enumerable.SequenceEqual(local.Project.GetConfigurations(), remote.Project.GetConfigurations()) && - Enumerable.SequenceEqual(local.Project.Commands, remote.Project.Commands) && - Enumerable.SequenceEqual(local.ProjectSearchPaths, remote.ProjectSearchPaths); - } - - protected override void SendPayload(ProjectSnapshot local, Action send) - { - send(new ProjectInformationMessage(local.Project, local.GlobalJsonPath, local.ProjectSearchPaths)); - } - - protected override void SetValue(ProjectSnapshot local, ProjectSnapshot remote) - { - remote.Project = local.Project; - remote.GlobalJsonPath = local.GlobalJsonPath; - remote.ProjectSearchPaths = local.ProjectSearchPaths; - } - - private class ProjectInformationMessage - { - public ProjectInformationMessage(Project project, - string gloablJsonPath, - IReadOnlyList projectSearchPaths) - { - Name = project.Name; - Frameworks = project.GetTargetFrameworks().Select(f => f.FrameworkName.ToPayload()).ToList(); - Configurations = project.GetConfigurations().ToList(); - Commands = project.Commands; - ProjectSearchPaths = projectSearchPaths; - GlobalJsonPath = gloablJsonPath; - } - - public string Name { get; } - - public IReadOnlyList Frameworks { get; } - - public IReadOnlyList Configurations { get; } - - public IDictionary Commands { get; } - - public IReadOnlyList ProjectSearchPaths { get; } - - public string GlobalJsonPath { get; } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ReferencesMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ReferencesMessenger.cs deleted file mode 100644 index 04a06af0b..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/ReferencesMessenger.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class ReferencesMessenger : Messenger - { - public ReferencesMessenger(Action transmit) - : base(MessageTypes.References, transmit) - { } - - protected override bool CheckDifference(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - return remote.FileReferences != null && - remote.ProjectReferences != null && - Enumerable.SequenceEqual(local.FileReferences, remote.FileReferences) && - Enumerable.SequenceEqual(local.ProjectReferences, remote.ProjectReferences); - } - - protected override void SendPayload(ProjectContextSnapshot local, Action send) - { - send(new ReferencesMessage - { - Framework = local.TargetFramework.ToPayload(), - ProjectReferences = local.ProjectReferences, - FileReferences = local.FileReferences - }); - } - - protected override void SetValue(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - remote.FileReferences = local.FileReferences; - remote.ProjectReferences = local.ProjectReferences; - } - - private class ReferencesMessage - { - public FrameworkData Framework { get; set; } - public IReadOnlyList FileReferences { get; set; } - public IReadOnlyList ProjectReferences { get; set; } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/SourcesMessenger.cs b/src/dotnet/commands/dotnet-projectmodel-server/Messengers/SourcesMessenger.cs deleted file mode 100644 index 66f7767df..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Messengers/SourcesMessenger.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server.Messengers -{ - internal class SourcesMessenger : Messenger - { - public SourcesMessenger(Action transmit) - : base(MessageTypes.Sources, transmit) - { } - - protected override bool CheckDifference(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - return remote.SourceFiles != null && - Enumerable.SequenceEqual(local.SourceFiles, remote.SourceFiles); - } - - protected override void SendPayload(ProjectContextSnapshot local, Action send) - { - send(new SourcesMessage - { - Framework = local.TargetFramework.ToPayload(), - Files = local.SourceFiles, - GeneratedFiles = new Dictionary() - }); - } - - protected override void SetValue(ProjectContextSnapshot local, ProjectContextSnapshot remote) - { - remote.SourceFiles = local.SourceFiles; - } - - private class SourcesMessage - { - public FrameworkData Framework { get; set; } - public IReadOnlyList Files { get; set; } - public IDictionary GeneratedFiles { get; set; } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs deleted file mode 100644 index 32c3854e5..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class DependencyDescription - { - private DependencyDescription() { } - - public string Name { get; private set; } - - public string DisplayName { get; private set; } - - public string Version { get; private set; } - - public string Path { get; private set; } - - public string Type { get; private set; } - - public bool Resolved { get; private set; } - - public IEnumerable Dependencies { get; private set; } - - public IEnumerable Errors { get; private set; } - - public IEnumerable Warnings { get; private set; } - - public override bool Equals(object obj) - { - var other = obj as DependencyDescription; - - return other != null && - Resolved == other.Resolved && - string.Equals(Name, other.Name) && - object.Equals(Version, other.Version) && - string.Equals(Path, other.Path) && - string.Equals(Type, other.Type) && - Enumerable.SequenceEqual(Dependencies, other.Dependencies) && - Enumerable.SequenceEqual(Errors, other.Errors) && - Enumerable.SequenceEqual(Warnings, other.Warnings); - } - - public override int GetHashCode() - { - // These objects are currently POCOs and we're overriding equals - // so that things like Enumerable.SequenceEqual just work. - return base.GetHashCode(); - } - - public static DependencyDescription Create(LibraryDescription library, - List diagnostics, - IDictionary exportsLookup) - { - var result = new DependencyDescription - { - Name = library.Identity.Name, - DisplayName = library.Identity.Name, - Version = (library.Identity.Version ?? new NuGetVersion("1.0.0")).ToNormalizedString(), - Type = library.Identity.Type.Value, - Resolved = library.Resolved, - Path = library.Path, - Dependencies = library.Dependencies.Select(dependency => GetDependencyItem(dependency, exportsLookup)), - Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error) - .Select(d => new DiagnosticMessageView(d)), - Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning) - .Select(d => new DiagnosticMessageView(d)) - }; - - var msbuildLibrary = library as MSBuildProjectDescription; - if (msbuildLibrary != null) - { - result.Path = msbuildLibrary.MSBuildProjectPath; - } - - return result; - } - - private static DependencyItem GetDependencyItem(LibraryRange dependency, - IDictionary exportsLookup) - { - return new DependencyItem - { - Name = dependency.Name, - Version = exportsLookup[dependency.Name].Library.Identity.Version?.ToNormalizedString() - }; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyItem.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyItem.cs deleted file mode 100644 index 1f014daff..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyItem.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class DependencyItem - { - public string Name { get; set; } - - public string Version { get; set; } - - public override bool Equals(object obj) - { - var other = obj as DependencyItem; - return other != null && - string.Equals(Name, other.Name) && - object.Equals(Version, other.Version); - } - - public override int GetHashCode() - { - // These objects are currently POCOs and we're overriding equals - // so that things like Enumerable.SequenceEqual just work. - return base.GetHashCode(); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageGroup.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageGroup.cs deleted file mode 100644 index c76adf86c..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageGroup.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class DiagnosticMessageGroup - { - public DiagnosticMessageGroup(IEnumerable diagnostics) - : this(framework: null, diagnostics: diagnostics) - { } - - public DiagnosticMessageGroup(NuGetFramework framework, IEnumerable diagnostics) - { - Framework = framework; - Diagnostics = diagnostics; - } - - public IEnumerable Diagnostics { get; } - - public NuGetFramework Framework { get; } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageView.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageView.cs deleted file mode 100644 index 8285d48ba..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticMessageView.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class DiagnosticMessageView - { - public DiagnosticMessageView(DiagnosticMessage data) - { - ErrorCode = data.ErrorCode; - SourceFilePath = data.SourceFilePath; - Message = data.Message; - Severity = data.Severity; - StartLine = data.StartLine; - StartColumn = data.StartColumn; - EndLine = data.EndLine; - EndColumn = data.EndColumn; - FormattedMessage = data.FormattedMessage; - - var description = data.Source as LibraryDescription; - if (description != null) - { - Source = new - { - Name = description.Identity.Name, - Version = description.Identity.Version?.ToString() - }; - } - } - - public string ErrorCode { get; } - - public string SourceFilePath { get; } - - public string Message { get; } - - public DiagnosticMessageSeverity Severity { get; } - - public int StartLine { get; } - - public int StartColumn { get; } - - public int EndLine { get; } - - public int EndColumn { get; } - - public string FormattedMessage { get; } - - public object Source { get; } - - public override bool Equals(object obj) - { - var other = obj as DiagnosticMessageView; - - return other != null && - Severity == other.Severity && - StartLine == other.StartLine && - StartColumn == other.StartColumn && - EndLine == other.EndLine && - EndColumn == other.EndColumn && - string.Equals(ErrorCode, other.ErrorCode, StringComparison.Ordinal) && - string.Equals(SourceFilePath, other.SourceFilePath, StringComparison.Ordinal) && - string.Equals(Message, other.Message, StringComparison.Ordinal) && - object.Equals(Source, other.Source); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticsListMessage.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticsListMessage.cs deleted file mode 100644 index dc66cd12d..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DiagnosticsListMessage.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class DiagnosticsListMessage - { - public DiagnosticsListMessage(IEnumerable diagnostics) : - this(diagnostics, frameworkData: null) - { - } - - public DiagnosticsListMessage(IEnumerable diagnostics, FrameworkData frameworkData) : - this(diagnostics.Select(msg => new DiagnosticMessageView(msg)).ToList(), frameworkData) - { - if (diagnostics == null) - { - throw new ArgumentNullException(nameof(diagnostics)); - } - } - - public DiagnosticsListMessage(IEnumerable diagnostics) : - this(diagnostics, frameworkData: null) - { - } - - public DiagnosticsListMessage(IEnumerable diagnostics, FrameworkData frameworkData) - { - if (diagnostics == null) - { - throw new ArgumentNullException(nameof(diagnostics)); - } - - Diagnostics = diagnostics; - Errors = diagnostics.Where(msg => msg.Severity == DiagnosticMessageSeverity.Error).ToList(); - Warnings = diagnostics.Where(msg => msg.Severity == DiagnosticMessageSeverity.Warning).ToList(); - Framework = frameworkData; - } - - public FrameworkData Framework { get; } - - [JsonIgnore] - public IEnumerable Diagnostics { get; } - - public IList Errors { get; } - - public IList Warnings { get; } - - public override bool Equals(object obj) - { - var other = obj as DiagnosticsListMessage; - - return other != null && - Enumerable.SequenceEqual(Errors, other.Errors) && - Enumerable.SequenceEqual(Warnings, other.Warnings) && - object.Equals(Framework, other.Framework); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/ErrorMessage.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/ErrorMessage.cs deleted file mode 100644 index 8623afae3..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/ErrorMessage.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class ErrorMessage - { - public string Message { get; set; } - public string Path { get; set; } - public int Line { get; set; } - public int Column { get; set; } - - public override bool Equals(object obj) - { - var payload = obj as ErrorMessage; - return payload != null && - string.Equals(Message, payload.Message, StringComparison.Ordinal) && - string.Equals(Path, payload.Path, StringComparison.OrdinalIgnoreCase) && - Line == payload.Line && - Column == payload.Column; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/FrameworkData.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/FrameworkData.cs deleted file mode 100644 index 258c1cb08..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/FrameworkData.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - public class FrameworkData - { - public string FrameworkName { get; set; } - public string FriendlyName { get; set; } - public string ShortName { get; set; } - public string RedistListPath { get; set; } - - public override bool Equals(object obj) - { - var other = obj as FrameworkData; - - return other != null && - string.Equals(FrameworkName, other.FrameworkName); - } - - public override int GetHashCode() - { - // These objects are currently POCOs and we're overriding equals - // so that things like Enumerable.SequenceEqual just work. - return base.GetHashCode(); - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/Message.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/Message.cs deleted file mode 100644 index 0c0bfe8f3..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/Message.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - internal class Message - { - public static Message FromPayload(string messageType, int contextId, object payload) - { - return new Message - { - MessageType = messageType, - ContextId = contextId, - Payload = payload is JToken ? (JToken)payload : JToken.FromObject(payload) - }; - } - - private Message() { } - - public string MessageType { get; set; } - - public string HostId { get; set; } - - public int ContextId { get; set; } = -1; - - public JToken Payload { get; set; } - - [JsonIgnore] - public ConnectionContext Sender { get; set; } - - public override string ToString() - { - return $"({HostId}, {MessageType}, {ContextId}) -> {Payload?.ToString(Formatting.Indented)}"; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/ProjectReferenceDescription.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/ProjectReferenceDescription.cs deleted file mode 100644 index 224837488..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/ProjectReferenceDescription.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.DotNet.ProjectModel.Server.Models -{ - internal class ProjectReferenceDescription - { - private ProjectReferenceDescription() { } - - public FrameworkData Framework { get; set; } - public string Name { get; set; } - public string Path { get; set; } - - public override bool Equals(object obj) - { - var other = obj as ProjectReferenceDescription; - return other != null && - string.Equals(Name, other.Name) && - string.Equals(Path, other.Path); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Create a ProjectReferenceDescription from given LibraryDescription. If the library doesn't - /// represent a project reference returns null. - /// - public static ProjectReferenceDescription Create(LibraryDescription library) - { - if (library is ProjectDescription) - { - return new ProjectReferenceDescription - { - Framework = library.Framework.ToPayload(), - Name = library.Identity.Name, - Path = library.Path - }; - } - else if (library is MSBuildProjectDescription) - { - return new ProjectReferenceDescription - { - Framework = library.Framework.ToPayload(), - Name = library.Identity.Name, - Path = ((MSBuildProjectDescription)library).MSBuildProjectPath, - }; - } - else - { - return null; - } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ProcessingQueue.cs b/src/dotnet/commands/dotnet-projectmodel-server/ProcessingQueue.cs deleted file mode 100644 index d3ceb13e9..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/ProcessingQueue.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.IO; -using System.Threading; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel.Server.Models; -using Newtonsoft.Json; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ProcessingQueue - { - private readonly BinaryReader _reader; - private readonly BinaryWriter _writer; - - public ProcessingQueue(Stream stream) - { - _reader = new BinaryReader(stream); - _writer = new BinaryWriter(stream); - } - - public event Action OnReceive; - - public void Start() - { - Reporter.Output.WriteLine("Start"); - new Thread(ReceiveMessages).Start(); - } - - public bool Send(Action writeAction) - { - lock (_writer) - { - try - { - writeAction(_writer); - return true; - } - catch (IOException ex) - { - // swallow - Reporter.Output.WriteLine($"Ignore {nameof(IOException)} during sending message: \"{ex.Message}\"."); - } - catch (Exception ex) - { - Reporter.Output.WriteLine($"Unexpected exception {ex.GetType().Name} during sending message: \"{ex.Message}\"."); - throw; - } - } - - return false; - } - - public bool Send(Message message) - { - return Send(_writer => - { - Reporter.Output.WriteLine($"OnSend ({message})"); - _writer.Write(JsonConvert.SerializeObject(message)); - }); - } - - private void ReceiveMessages() - { - try - { - while (true) - { - var content = _reader.ReadString(); - var message = JsonConvert.DeserializeObject(content); - - Reporter.Output.WriteLine($"OnReceive ({message})"); - OnReceive(message); - } - } - catch (IOException ex) - { - Reporter.Output.WriteLine($"Ignore {nameof(IOException)} during receiving messages: \"{ex}\"."); - } - catch (Exception ex) - { - Reporter.Error.WriteLine($"Unexpected exception {ex.GetType().Name} during receiving messages: \"{ex}\"."); - } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Program.cs b/src/dotnet/commands/dotnet-projectmodel-server/Program.cs deleted file mode 100644 index 3211ed15d..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Program.cs +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Net; -using System.Net.Sockets; -using Microsoft.DotNet.Cli.CommandLine; -using Microsoft.DotNet.Cli.Utils; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - public class ProjectModelServerCommand - { - private readonly Dictionary _projects; - private readonly DesignTimeWorkspace _workspaceContext; - private readonly ProtocolManager _protocolManager; - private readonly string _hostName; - private readonly int _port; - private Socket _listenSocket; - - public ProjectModelServerCommand(int port, string hostName) - { - _port = port; - _hostName = hostName; - _protocolManager = new ProtocolManager(maxVersion: 4); - _workspaceContext = new DesignTimeWorkspace(ProjectReaderSettings.ReadFromEnvironment()); - _projects = new Dictionary(); - } - - public static int Run(string[] args) - { - var app = new CommandLineApplication(); - app.Name = "dotnet-projectmodel-server"; - app.Description = ".NET Project Model Server"; - app.FullName = ".NET Design Time Server"; - app.Description = ".NET Design Time Server"; - app.HelpOption("-?|-h|--help"); - - var verbose = app.Option("--verbose", "Verbose ouput", CommandOptionType.NoValue); - var hostpid = app.Option("--host-pid", "The process id of the host", CommandOptionType.SingleValue); - var hostname = app.Option("--host-name", "The name of the host", CommandOptionType.SingleValue); - var port = app.Option("--port", "The TCP port used for communication", CommandOptionType.SingleValue); - - app.OnExecute(() => - { - try - { - if (!MonitorHostProcess(hostpid)) - { - return 1; - } - - var intPort = CheckPort(port); - if (intPort == -1) - { - return 1; - } - - if (!hostname.HasValue()) - { - Reporter.Error.WriteLine($"Option \"{hostname.LongName}\" is missing."); - return 1; - } - - var program = new ProjectModelServerCommand(intPort, hostname.Value()); - program.OpenChannel(); - } - catch (Exception ex) - { - Reporter.Error.WriteLine($"Unhandled exception in server main: {ex}"); - throw; - } - - return 0; - }); - - return app.Execute(args); - } - - public void OpenChannel() - { - _listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - _listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, _port)); - _listenSocket.Listen(10); - - Reporter.Output.WriteLine($"Process ID {Process.GetCurrentProcess().Id}"); - Reporter.Output.WriteLine($"Listening on port {_port}"); - - while (true) - { - var acceptSocket = _listenSocket.Accept(); - Reporter.Output.WriteLine($"Client accepted {acceptSocket.LocalEndPoint}"); - - var connection = new ConnectionContext(acceptSocket, - _hostName, - _protocolManager, - _workspaceContext, - _projects); - - connection.QueueStart(); - } - } - - public void Shutdown() - { - if (_listenSocket.Connected) - { - _listenSocket.Shutdown(SocketShutdown.Both); - } - } - - private static int CheckPort(CommandOption port) - { - if (!port.HasValue()) - { - Reporter.Error.WriteLine($"Option \"{port.LongName}\" is missing."); - } - - int result; - if (int.TryParse(port.Value(), out result)) - { - return result; - } - else - { - Reporter.Error.WriteLine($"Option \"{port.LongName}\" is not a valid Int32 value."); - return -1; - } - } - - private static bool MonitorHostProcess(CommandOption host) - { - if (!host.HasValue()) - { - Console.Error.WriteLine($"Option \"{host.LongName}\" is missing."); - return false; - } - - int hostPID; - if (int.TryParse(host.Value(), out hostPID)) - { - var hostProcess = Process.GetProcessById(hostPID); - hostProcess.EnableRaisingEvents = true; - hostProcess.Exited += (s, e) => - { - Process.GetCurrentProcess().Kill(); - }; - - Reporter.Output.WriteLine($"Server will exit when process {hostPID} exits."); - return true; - } - else - { - Reporter.Error.WriteLine($"Option \"{host.LongName}\" is not a valid Int32 value."); - return false; - } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs b/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs deleted file mode 100644 index 47f4a0390..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel.Server.Helpers; -using Microsoft.DotNet.ProjectModel.Server.Messengers; -using Microsoft.DotNet.ProjectModel.Server.Models; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ProjectManager - { - private readonly object _processingLock = new object(); - private readonly Queue _inbox = new Queue(); - private readonly ProtocolManager _protocolManager; - - private ConnectionContext _initializedContext; - - // triggers - private readonly Trigger _appPath = new Trigger(); - private readonly Trigger _configure = new Trigger(); - private readonly Trigger _refreshDependencies = new Trigger(); - private readonly Trigger _filesChanged = new Trigger(); - - private ProjectSnapshot _local = new ProjectSnapshot(); - private ProjectSnapshot _remote = new ProjectSnapshot(); - - private readonly DesignTimeWorkspace _workspaceContext; - private int? _contextProtocolVersion; - - private readonly List> _messengers; - - private ProjectDiagnosticsMessenger _projectDiagnosticsMessenger; - private GlobalErrorMessenger _globalErrorMessenger; - private ProjectInformationMessenger _projectInforamtionMessenger; - - public ProjectManager( - int contextId, - DesignTimeWorkspace workspaceContext, - ProtocolManager protocolManager) - { - Id = contextId; - _workspaceContext = workspaceContext; - _protocolManager = protocolManager; - - _messengers = new List> - { - new ReferencesMessenger(Transmit), - new DependenciesMessenger(Transmit), - new DependencyDiagnosticsMessenger(Transmit), - new CompilerOptionsMessenger(Transmit), - new SourcesMessenger(Transmit) - }; - - _projectDiagnosticsMessenger = new ProjectDiagnosticsMessenger(Transmit); - _globalErrorMessenger = new GlobalErrorMessenger(Transmit); - _projectInforamtionMessenger = new ProjectInformationMessenger(Transmit); - } - - public int Id { get; } - - public string ProjectPath { get { return _appPath.Value; } } - - public int ProtocolVersion - { - get - { - if (_contextProtocolVersion.HasValue) - { - return _contextProtocolVersion.Value; - } - else - { - return _protocolManager.CurrentVersion; - } - } - } - - public void OnReceive(Message message) - { - lock (_inbox) - { - _inbox.Enqueue(message); - } - - ThreadPool.QueueUserWorkItem(state => ((ProjectManager)state).ProcessLoop(), this); - } - - private void Transmit(string messageType, object payload) - { - var message = Message.FromPayload(messageType, Id, payload); - _initializedContext.Transmit(message); - } - - private void ProcessLoop() - { - if (!Monitor.TryEnter(_processingLock)) - { - return; - } - - try - { - lock (_inbox) - { - if (!_inbox.Any()) - { - return; - } - } - - DoProcessLoop(); - } - catch (Exception ex) - { - Reporter.Error.WriteLine($"A unexpected exception occurred: {ex}"); - - var error = new ErrorMessage - { - Message = ex.Message - }; - - var fileFormatException = ex as FileFormatException; - if (fileFormatException != null) - { - error.Path = fileFormatException.Path; - error.Line = fileFormatException.Line; - error.Column = fileFormatException.Column; - } - - var message = Message.FromPayload(MessageTypes.Error, Id, error); - - _initializedContext.Transmit(message); - _remote.GlobalErrorMessage = error; - } - finally - { - Monitor.Exit(_processingLock); - } - } - - private void DoProcessLoop() - { - while (true) - { - DrainInbox(); - - UpdateProject(); - SendOutgingMessages(); - - lock (_inbox) - { - if (_inbox.Count == 0) - { - return; - } - } - } - } - - private void DrainInbox() - { - Reporter.Output.WriteLine("Begin draining inbox."); - - while (ProcessMessage()) { } - - Reporter.Output.WriteLine("Finish draining inbox."); - } - - private bool ProcessMessage() - { - Message message; - - lock (_inbox) - { - if (!_inbox.Any()) - { - return false; - } - - message = _inbox.Dequeue(); - Debug.Assert(message != null); - } - - Reporter.Output.WriteLine($"Received {message.MessageType}"); - - switch (message.MessageType) - { - case MessageTypes.Initialize: - Initialize(message); - break; - case MessageTypes.ChangeConfiguration: - // TODO: what if the payload is null or represent empty string? - _configure.Value = message.Payload.GetValue("Configuration"); - break; - case MessageTypes.RefreshDependencies: - // In the case of RefreshDependencies request, the cache will not be reset in any case. The value - // is set so as to trigger refresh action in later loop. - _refreshDependencies.Value = false; - break; - case MessageTypes.RestoreComplete: - // In the case of RestoreComplete request, the value of the 'Reset' property in payload will determine - // if the cache should be reset. If the property doesn't exist, cache will be reset. - _refreshDependencies.Value = message.Payload.HasValues ? message.Payload.Value("Reset") : true; - break; - case MessageTypes.FilesChanged: - _filesChanged.Value = 0; - break; - } - - return true; - } - - private void Initialize(Message message) - { - if (_initializedContext != null) - { - Reporter.Output.WriteLine($"Received {message.MessageType} message more than once for {_appPath.Value}"); - return; - } - - _initializedContext = message.Sender; - _appPath.Value = message.Payload.GetValue("ProjectFolder"); - _configure.Value = message.Payload.GetValue("Configuration") ?? "Debug"; - - var version = message.Payload.GetValue("Version"); - if (version != 0 && !_protocolManager.EnvironmentOverridden) - { - _contextProtocolVersion = Math.Min(version, _protocolManager.MaxVersion); - Reporter.Output.WriteLine($"Set context protocol version to {_contextProtocolVersion.Value}"); - } - } - - private bool UpdateProject() - { - ProjectSnapshot newSnapshot = null; - - if (_appPath.WasAssigned || _configure.WasAssigned || _filesChanged.WasAssigned || _refreshDependencies.WasAssigned) - { - _appPath.ClearAssigned(); - _configure.ClearAssigned(); - _filesChanged.ClearAssigned(); - - bool resetCache = _refreshDependencies.WasAssigned ? _refreshDependencies.Value : false; - _refreshDependencies.ClearAssigned(); - - newSnapshot = ProjectSnapshot.Create(_appPath.Value, - _configure.Value, - _workspaceContext, - _remote.ProjectSearchPaths, - clearWorkspaceContextCache: resetCache); - } - - if (newSnapshot == null) - { - return false; - } - - _local = newSnapshot; - - return true; - } - - private void SendOutgingMessages() - { - _projectInforamtionMessenger.UpdateRemote(_local, _remote); - _projectDiagnosticsMessenger.UpdateRemote(_local, _remote); - - var unprocessedFrameworks = new HashSet(_remote.ProjectContexts.Keys); - foreach (var pair in _local.ProjectContexts) - { - ProjectContextSnapshot localProjectSnapshot = pair.Value; - ProjectContextSnapshot remoteProjectSnapshot; - - if (!_remote.ProjectContexts.TryGetValue(pair.Key, out remoteProjectSnapshot)) - { - remoteProjectSnapshot = new ProjectContextSnapshot(); - _remote.ProjectContexts[pair.Key] = remoteProjectSnapshot; - } - - unprocessedFrameworks.Remove(pair.Key); - - foreach (var messenger in _messengers) - { - messenger.UpdateRemote(localProjectSnapshot, - remoteProjectSnapshot); - } - } - - // Remove all processed frameworks from the remote view - foreach (var framework in unprocessedFrameworks) - { - _remote.ProjectContexts.Remove(framework); - } - - _globalErrorMessenger.UpdateRemote(_local, _remote); - } - - private class Trigger - { - private TValue _value; - - public bool WasAssigned { get; private set; } - - public void ClearAssigned() - { - WasAssigned = false; - } - - public TValue Value - { - get { return _value; } - set - { - WasAssigned = true; - _value = value; - } - } - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ProtocolManager.cs b/src/dotnet/commands/dotnet-projectmodel-server/ProtocolManager.cs deleted file mode 100644 index dd7de15c9..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/ProtocolManager.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel.Server.Models; - -namespace Microsoft.DotNet.ProjectModel.Server -{ - internal class ProtocolManager - { - /// - /// Environment variable for overriding protocol. - /// - public const string EnvDthProtocol = "DTH_PROTOCOL"; - - public ProtocolManager(int maxVersion) - { - MaxVersion = maxVersion; - - // initialized to the highest supported version or environment overridden value - int? protocol = GetProtocolVersionFromEnvironment(); - - if (protocol.HasValue) - { - CurrentVersion = protocol.Value; - EnvironmentOverridden = true; - } - else - { - CurrentVersion = 4; - } - } - - public int MaxVersion { get; } - - public int CurrentVersion { get; private set; } - - public bool EnvironmentOverridden { get; } - - public bool IsProtocolNegotiation(Message message) - { - return message?.MessageType == MessageTypes.ProtocolVersion; - } - - public void Negotiate(Message message) - { - if (!IsProtocolNegotiation(message)) - { - return; - } - - Reporter.Output.WriteLine("Initializing the protocol negotiation."); - - if (EnvironmentOverridden) - { - Reporter.Output.WriteLine($"DTH protocol negotiation is override by environment variable {EnvDthProtocol} and set to {CurrentVersion}."); - return; - } - - var tokenValue = message.Payload?["Version"]; - if (tokenValue == null) - { - Reporter.Output.WriteLine("Protocol negotiation failed. Version property is missing in payload."); - return; - } - - var preferredVersion = tokenValue.ToObject(); - if (preferredVersion == 0) - { - // the preferred version can't be zero. either property is missing or the the payload is corrupted. - Reporter.Output.WriteLine("Protocol negotiation failed. Protocol version 0 is invalid."); - return; - } - - CurrentVersion = Math.Min(preferredVersion, MaxVersion); - Reporter.Output.WriteLine($"Protocol negotiation successed. Use protocol {CurrentVersion}"); - - if (message.Sender != null) - { - Reporter.Output.WriteLine("Respond to protocol negotiation."); - message.Sender.Transmit(Message.FromPayload( - MessageTypes.ProtocolVersion, - 0, - new { Version = CurrentVersion })); - } - else - { - Reporter.Output.WriteLine($"{nameof(Message.Sender)} is null."); - } - } - - private static int? GetProtocolVersionFromEnvironment() - { - // look for the environment variable DTH_PROTOCOL, if it is set override the protocol version. - // this is for debugging. - var strProtocol = Environment.GetEnvironmentVariable(EnvDthProtocol); - int intProtocol = -1; - if (!string.IsNullOrEmpty(strProtocol) && Int32.TryParse(strProtocol, out intProtocol)) - { - return intProtocol; - } - - return null; - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/DthTestClient.cs b/test/dotnet-projectmodel-server.Tests/DthTestClient.cs deleted file mode 100644 index 08a1cf224..000000000 --- a/test/dotnet-projectmodel-server.Tests/DthTestClient.cs +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public class DthTestClient : IDisposable - { - private readonly string _hostId; - private readonly BinaryReader _reader; - private readonly BinaryWriter _writer; - private readonly NetworkStream _networkStream; - private readonly BlockingCollection _messageQueue; - private readonly CancellationTokenSource _readCancellationToken; - private readonly TimeSpan _defaultTimeout = TimeSpan.FromSeconds(20); - - // Keeps track of initialized project contexts - // REVIEW: This needs to be exposed if we ever create 2 clients in order to simulate how build - // works in visual studio - private readonly Dictionary _projectContexts = new Dictionary(); - private int _nextContextId; - private readonly Socket _socket; - - public DthTestClient(DthTestServer server) - { - // Avoid Socket exception 10006 on Linux - Thread.Sleep(100); - - _socket = new Socket(AddressFamily.InterNetwork, - SocketType.Stream, - ProtocolType.Tcp); - - _socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); - - _hostId = server.HostId; - - _networkStream = new NetworkStream(_socket); - _reader = new BinaryReader(_networkStream); - _writer = new BinaryWriter(_networkStream); - - _messageQueue = new BlockingCollection(); - - _readCancellationToken = new CancellationTokenSource(); - Task.Run(() => ReadMessage(_readCancellationToken.Token), _readCancellationToken.Token); - } - - public void SendPayload(Project project, string messageType) - { - SendPayload(project.ProjectDirectory, messageType); - } - - public void SendPayload(string projectPath, string messageType) - { - SendPayload(projectPath, messageType, new { }); - } - - public void SendPayload(string projectPath, string messageType, object payload) - { - int contextId; - if (!_projectContexts.TryGetValue(projectPath, out contextId)) - { - Assert.True(false, $"Unable to resolve context for {projectPath}"); - } - - SendPayload(contextId, messageType, payload); - } - - public void SendPayload(int contextId, string messageType) - { - SendPayload(contextId, messageType, new { }); - } - - public void SendPayload(int contextId, string messageType, object payload) - { - lock (_writer) - { - var message = new - { - ContextId = contextId, - HostId = _hostId, - MessageType = messageType, - Payload = payload - }; - _writer.Write(JsonConvert.SerializeObject(message)); - } - } - - public int Initialize(string projectPath) - { - var contextId = _nextContextId++; - - _projectContexts[projectPath] = contextId; - SendPayload(contextId, MessageTypes.Initialize, new { ProjectFolder = projectPath }); - - return contextId; - } - - public int Initialize(string projectPath, int protocolVersion) - { - var contextId = _nextContextId++; - - _projectContexts[projectPath] = contextId; - SendPayload(contextId, MessageTypes.Initialize, new { ProjectFolder = projectPath, Version = protocolVersion }); - - return contextId; - } - - public int Initialize(string projectPath, int protocolVersion, string configuration) - { - var contextId = _nextContextId++; - - _projectContexts[projectPath] = contextId; - SendPayload(contextId, MessageTypes.Initialize, new { ProjectFolder = projectPath, Version = protocolVersion, Configuration = configuration }); - - return contextId; - } - - public void SetProtocolVersion(int version) - { - SendPayload(0, MessageTypes.ProtocolVersion, new { Version = version }); - } - - public List DrainMessage(int count) - { - var result = new List(); - while (count > 0) - { - result.Add(GetResponse(timeout: _defaultTimeout)); - count--; - } - - return result; - } - - public List DrainAllMessages() - { - return DrainAllMessages(_defaultTimeout); - } - - /// - /// Read all messages from pipeline till timeout - /// - /// The timeout - /// All the messages in a list - public List DrainAllMessages(TimeSpan timeout) - { - var result = new List(); - while (true) - { - try - { - result.Add(GetResponse(timeout)); - } - catch (TimeoutException) - { - return result; - } - catch (Exception) - { - throw; - } - } - } - - /// - /// Read messages from pipeline until the first match - /// ] - /// A message type - /// The first match message - public DthMessage DrainTillFirst(string type) - { - return DrainTillFirst(type, _defaultTimeout); - } - - /// - /// Read messages from pipeline until the first match - /// - /// A message type - /// Timeout for each read - /// The first match message - public DthMessage DrainTillFirst(string type, TimeSpan timeout) - { - while (true) - { - var next = GetResponse(timeout); - if (next.MessageType == type) - { - return next; - } - } - } - - /// - /// Read messages from pipeline until the first match - /// - /// A message type - /// Timeout - /// All the messages read before the first match - /// The first match - public DthMessage DrainTillFirst(string type, TimeSpan timeout, out List leadingMessages) - { - leadingMessages = new List(); - while (true) - { - var next = GetResponse(timeout); - if (next.MessageType == type) - { - return next; - } - else - { - leadingMessages.Add(next); - } - } - } - - public void Dispose() - { - _reader.Dispose(); - _writer.Dispose(); - _networkStream.Dispose(); - _readCancellationToken.Cancel(); - - try - { - _socket.Shutdown(SocketShutdown.Both); - } - catch (SocketException ex) - { - // Swallow this error for now. - // This is a temporary fix for a random failure on CI. The issue happens on Windowx x86 - // only. - Console.Error.WriteLine($"Exception thrown durning socket shutting down: {ex.SocketErrorCode}."); - } - } - - private void ReadMessage(CancellationToken cancellationToken) - { - while (true) - { - try - { - if (cancellationToken.IsCancellationRequested) - { - return; - } - - var content = _reader.ReadString(); - var message = JsonConvert.DeserializeObject(content); - - _messageQueue.Add(message); - } - catch (IOException) - { - // swallow - } - catch (JsonSerializationException deserializException) - { - throw new InvalidOperationException( - $"Fail to deserailze data into {nameof(DthMessage)}.", - deserializException); - } - catch (Exception ex) - { - throw ex; - } - } - } - - private DthMessage GetResponse(TimeSpan timeout) - { - DthMessage message; - - if (_messageQueue.TryTake(out message, timeout)) - { - return message; - } - else - { - throw new TimeoutException($"Response time out after {timeout.TotalSeconds} seconds."); - } - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/DthTestServer.cs b/test/dotnet-projectmodel-server.Tests/DthTestServer.cs deleted file mode 100644 index 9c17737d2..000000000 --- a/test/dotnet-projectmodel-server.Tests/DthTestServer.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public class DthTestServer : IDisposable - { - private readonly ProjectModelServerCommand _program; - private readonly Thread _thread; - - public DthTestServer() - { - Port = FindFreePort(); - HostId = Guid.NewGuid().ToString(); - - _program = new ProjectModelServerCommand(Port, HostId); - - _thread = new Thread(() => { _program.OpenChannel(); }) { IsBackground = true }; - _thread.Start(); - } - - public string HostId { get; } - - public int Port { get; } - - public void Dispose() - { - try - { - _program.Shutdown(); - } - catch (InvalidOperationException) - { - // swallow the exception if the process had been terminated. - } - } - - private static int FindFreePort() - { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - return ((IPEndPoint)socket.LocalEndPoint).Port; - } - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/DthTests.cs b/test/dotnet-projectmodel-server.Tests/DthTests.cs deleted file mode 100644 index 77db2d429..000000000 --- a/test/dotnet-projectmodel-server.Tests/DthTests.cs +++ /dev/null @@ -1,789 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.TestFramework; -using Microsoft.DotNet.Tools.Test.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public class DthTests : TestBase - { - private readonly TestAssetsManager _testAssetsManager; - - public DthTests() - { - _testAssetsManager = new TestAssetsManager( - Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "DthTestProjects", "src")); - } - - [Fact] - public void DthStartup_GetProjectInformation() - { - var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp"); - Assert.NotNull(projectPath); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - - var projectInformation = client.DrainTillFirst(MessageTypes.ProjectInformation) - .EnsureSource(server, client) - .RetrievePayloadAs() - .AssertProperty("Name", "EmptyConsoleApp"); - - projectInformation.RetrievePropertyAs("Configurations") - .AssertJArrayCount(2) - .AssertJArrayContains("Debug") - .AssertJArrayContains("Release"); - - var frameworkShortNames = projectInformation.RetrievePropertyAs("Frameworks") - .AssertJArrayCount(2) - .Select(f => f["ShortName"].Value()); - - Assert.Contains("netcoreapp1.0", frameworkShortNames); - Assert.Contains("dnx451", frameworkShortNames); - } - } - - [Theory] - [InlineData(MessageTypes.RefreshDependencies, null)] - [InlineData(MessageTypes.RestoreComplete, null)] - [InlineData(MessageTypes.RestoreComplete, true)] - [InlineData(MessageTypes.RestoreComplete, false)] - public void RefreshDependenciesResultsAreConsistent(string messageType, bool? clearCache) - { - var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyNetCoreApp"); - Assert.True(Directory.Exists(projectPath)); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - var originalDependencies = client.DrainMessage(7).Single(m => m.MessageType == MessageTypes.Dependencies) - .RetrievePayloadAs(); - - if (clearCache.HasValue) - { - client.SendPayload(projectPath, messageType, new { Reset = clearCache.Value }); - } - else - { - client.SendPayload(projectPath, messageType); - } - - var refreshedDependencies = client.DrainTillFirst(MessageTypes.Dependencies).Payload.ToString(); - - Assert.Equal(originalDependencies.ToString(), refreshedDependencies.ToString()); - } - } - - [Fact] - public void DependencyDiagnsoticsAfterDependencies() - { - var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp"); - Assert.NotNull(projectPath); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - var messages = client.DrainMessage(12) - .Select(message => message.MessageType) - .ToArray(); - - var expectDependencies = true; - var expectDependencyDiagnostics = false; - for (var i = 0; i < messages.Length; ++i) - { - if (messages[i] == MessageTypes.Dependencies) - { - Assert.True(expectDependencies); - expectDependencies = false; - expectDependencyDiagnostics = true; - } - else if (messages[i] == MessageTypes.DependencyDiagnostics) - { - Assert.True(expectDependencyDiagnostics); - expectDependencyDiagnostics = false; - break; - } - } - - Assert.False(expectDependencies); - Assert.False(expectDependencyDiagnostics); - } - } - - [Theory] - [InlineData(4, 4)] - [InlineData(5, 4)] - [InlineData(3, 3)] - public void DthStartup_ProtocolNegotiation(int requestVersion, int expectVersion) - { - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.SetProtocolVersion(requestVersion); - - var response = client.DrainTillFirst(MessageTypes.ProtocolVersion, TimeSpan.FromDays(1)); - response.EnsureSource(server, client); - - Assert.Equal(expectVersion, response.Payload["Version"]?.Value()); - } - } - - [Fact] - public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed() - { - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.SetProtocolVersion(0); - - Assert.Throws(() => - { - client.DrainTillFirst(MessageTypes.ProtocolVersion, timeout: TimeSpan.FromSeconds(1)); - }); - } - } - - [Theory] - [InlineData("Project", "UnresolvedProjectSample", "EmptyLibrary", "Project")] - [InlineData("Package", "UnresolvedPackageSample", "NoSuchPackage", null)] - [InlineData("Package", "IncompatiblePackageSample", "Microsoft.Web.Administration", "Package")] - public void DthCompilation_Initialize_UnresolvedDependency(string referenceType, - string testProjectName, - string expectedUnresolvedDependency, - string expectedUnresolvedType) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - Console.WriteLine("Test is skipped on Linux"); - return; - } - - var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, testProjectName); - Assert.NotNull(projectPath); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - - var referencesMessage = client.DrainTillFirst(MessageTypes.References, TimeSpan.FromDays(1)) - .EnsureSource(server, client); - - if (referenceType == "Project") - { - var expectedUnresolvedProjectPath = Path.Combine(Path.GetDirectoryName(projectPath), - expectedUnresolvedDependency, - Project.FileName); - - referencesMessage.RetrievePayloadAs() - .RetrievePropertyAs("ProjectReferences") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("Name", expectedUnresolvedDependency) - .AssertProperty("Path", expectedUnresolvedProjectPath); - } - else if (referenceType == "Package") - { - referencesMessage.RetrievePayloadAs() - .RetrievePropertyAs("ProjectReferences") - .AssertJArrayCount(0); - } - - var unresolveDependency = client.DrainTillFirst(MessageTypes.Dependencies) - .EnsureSource(server, client) - .RetrieveDependency(expectedUnresolvedDependency); - - unresolveDependency.AssertProperty("Name", expectedUnresolvedDependency) - .AssertProperty("DisplayName", expectedUnresolvedDependency) - .AssertProperty("Resolved", false) - .AssertProperty("Type", expectedUnresolvedType); - - if (expectedUnresolvedType == "Project") - { - unresolveDependency.AssertProperty("Path", Path.Combine(Path.GetDirectoryName(projectPath), - expectedUnresolvedDependency, - Project.FileName)); - } - else - { - Assert.False(unresolveDependency["Path"].HasValues); - } - } - } - - [Fact] - public void DthNegative_BrokenProjectPathInLockFile() - { - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - // After restore the project is copied to another place so that - // the relative path in project lock file is invalid. - var movedProjectPath = _testAssetsManager.CreateTestInstance("BrokenProjectPathSample") - .WithLockFiles() - .TestRoot; - - client.Initialize(movedProjectPath); - - client.DrainTillFirst("Dependencies") - .RetrieveDependency("EmptyLibrary") - .AssertProperty("Errors", errorsArray => errorsArray.Count == 1) - .AssertProperty("Warnings", warningsArray => warningsArray.Count == 0) - .AssertProperty("Name", "EmptyLibrary") - .AssertProperty("Resolved", false); - - client.DrainTillFirst("DependencyDiagnostics") - .RetrieveDependencyDiagnosticsCollection() - .RetrieveDependencyDiagnosticsErrorAt(0) - .AssertProperty("FormattedMessage", message => message.Contains("error NU1002")) - .RetrievePropertyAs("Source") - .AssertProperty("Name", "EmptyLibrary"); - } - } - - [Fact] - public void DthDependencies_UpdateGlobalJson_RefreshDependencies() - { - var assetsManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer")); - var projectPath = assetsManager.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot; - Assert.True(Directory.Exists(projectPath)); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - var testProject = Path.Combine(projectPath, "home", "src", "MainProject"); - - client.Initialize(testProject); - - client.DrainTillFirst("ProjectInformation") - .RetrievePayloadAs() - .RetrievePropertyAs("ProjectSearchPaths") - .AssertJArrayCount(2); - - client.DrainTillFirst("Dependencies") - .RetrieveDependency("Newtonsoft.Json") - .AssertProperty("Type", "Project") - .AssertProperty("Resolved", true) - .AssertProperty("Errors", array => array.Count == 0, _ => "Dependency shouldn't contain any error."); - - client.DrainTillFirst("DependencyDiagnostics") - .RetrievePayloadAs() - .AssertProperty("Errors", array => array.Count == 0) - .AssertProperty("Warnings", array => array.Count == 0); - - // Overwrite the global.json to remove search path to ext - File.WriteAllText( - Path.Combine(projectPath, "home", GlobalSettings.FileName), - JsonConvert.SerializeObject(new { projects = new string[] { "src" } })); - - client.SendPayload(testProject, "RefreshDependencies"); - - client.DrainTillFirst("ProjectInformation") - .RetrievePayloadAs() - .RetrievePropertyAs("ProjectSearchPaths") - .AssertJArrayCount(1) - .AssertJArrayElement(0, Path.Combine(projectPath, "home", "src")); - - client.DrainTillFirst("Dependencies") - .RetrieveDependency("Newtonsoft.Json") - .AssertProperty("Resolved", false) - .AssertProperty("Type", "Project") - .RetrievePropertyAs("Errors") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("ErrorCode", ErrorCodes.NU1010); - - client.DrainTillFirst("DependencyDiagnostics") - .RetrieveDependencyDiagnosticsCollection() - .RetrieveDependencyDiagnosticsErrorAt(0) - .AssertProperty("ErrorCode", ErrorCodes.NU1010); - - var restoreCommand = new RestoreCommand(); - restoreCommand.WorkingDirectory = projectPath; - restoreCommand.Execute().Should().Pass(); - - client.SendPayload(testProject, "RefreshDependencies"); - - client.DrainTillFirst("Dependencies") - .RetrieveDependency("Newtonsoft.Json") - .AssertProperty("Resolved", true) - .AssertProperty("Type", "Package") - .RetrievePropertyAs("Errors") - .AssertJArrayCount(0); - - client.DrainTillFirst("DependencyDiagnostics") - .RetrievePayloadAs() - .AssertProperty("Errors", array => array.Count == 0) - .AssertProperty("Warnings", array => array.Count == 0); - - // Overwrite the global.json to add search path to ext back - File.WriteAllText( - Path.Combine(projectPath, "home", GlobalSettings.FileName), - JsonConvert.SerializeObject(new { projects = new string[] { "src", "../ext" } })); - - client.SendPayload(testProject, "RefreshDependencies"); - - client.DrainTillFirst("ProjectInformation") - .RetrievePayloadAs() - .RetrievePropertyAs("ProjectSearchPaths") - .AssertJArrayCount(2) - .AssertJArrayElement(0, Path.Combine(projectPath, "home", "src")) - .AssertJArrayElement(1, Path.Combine(projectPath, "ext")); - - client.DrainTillFirst("Dependencies") - .RetrieveDependency("Newtonsoft.Json") - .AssertProperty("Resolved", false) - .AssertProperty("Type", "Package") - .RetrievePropertyAs("Errors") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("ErrorCode", ErrorCodes.NU1010); - - client.DrainTillFirst("DependencyDiagnostics") - .RetrieveDependencyDiagnosticsCollection() - .RetrieveDependencyDiagnosticsErrorAt(0) - .AssertProperty("ErrorCode", ErrorCodes.NU1010); - } - } - - [Fact] - public void DthStartup_OpenProjectBeforeRestore() - { - var projectPath = _testAssetsManager.CreateTestInstance("EmptyConsoleApp").TestRoot; - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - var messages = client.DrainMessage(12); - Assert.False(messages.Any(msg => msg.MessageType == MessageTypes.Error)); - - var dependencyDiagnostics = messages.Where(msg => msg.MessageType == MessageTypes.DependencyDiagnostics); - Assert.Equal(2, dependencyDiagnostics.Count()); - - foreach (var message in dependencyDiagnostics) - { - message.RetrievePayloadAs() - .RetrievePropertyAs("Errors") - .AssertJArrayContains(error => error["ErrorCode"].Value() == ErrorCodes.NU1009); - } - } - } - - [Fact] - public void InvalidProjectJson() - { - var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"); - var assetsManager = new TestAssetsManager(testAssetsPath); - var testSource = assetsManager.CreateTestInstance("IncorrectProjectJson").TestRoot; - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyLibrary")); - client.Initialize(testSource); - - // Error for invalid project.json - var messages = client.DrainMessage(8); - messages.Single(msg => msg.MessageType == MessageTypes.Error) - .Payload.AsJObject() - .AssertProperty("Path", v => v.Contains("IncorrectProjectJson")); - - // Successfully initialize the other project - messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation) - .Payload.AsJObject() - .AssertProperty("Name", v => string.Equals(v, "EmptyLibrary", StringComparison.Ordinal)); - - // Successfully initialize another project afterwards - client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp")); - client.DrainTillFirst(MessageTypes.ProjectInformation) - .Payload.AsJObject() - .AssertProperty("Name", v => string.Equals(v, "EmptyConsoleApp", StringComparison.Ordinal)); - } - } - - [Fact] - public void InvalidGlobalJson() - { - var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"); - var assetsManager = new TestAssetsManager(testAssetsPath); - var testSource = assetsManager.CreateTestInstance("IncorrectGlobalJson"); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(Path.Combine(testSource.TestRoot, "src", "Project1")); - - client.DrainTillFirst(MessageTypes.Error) - .Payload.AsJObject() - .AssertProperty("Path", v => v.Contains("InvalidGlobalJson")); - } - } - - [Fact] - public void RecoverFromGlobalError() - { - var testProject = _testAssetsManager.CreateTestInstance("EmptyConsoleApp") - .WithLockFiles() - .TestRoot; - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - var projectFile = Path.Combine(testProject, Project.FileName); - var content = File.ReadAllText(projectFile); - File.WriteAllText(projectFile, content + "}"); - - client.Initialize(testProject); - client.DrainTillFirst(MessageTypes.Error); - - File.WriteAllText(projectFile, content); - client.SendPayload(testProject, MessageTypes.FilesChanged); - client.DrainTillFirst(MessageTypes.Error) - .Payload.AsJObject() - .AssertProperty("Message", null as string); - } - } - - [Theory] - [InlineData(500, true)] - [InlineData(3000, false)] - public void WaitForLockFileReleased(int occupyFileFor, bool expectSuccess) - { - var testProject = _testAssetsManager.CreateTestInstance("EmptyConsoleApp") - .WithLockFiles() - .TestRoot; - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - var lockFilePath = Path.Combine(testProject, LockFile.FileName); - var lockFileContent = File.ReadAllText(lockFilePath); - var fs = new FileStream(lockFilePath, FileMode.Create, FileAccess.Write, FileShare.None); - - // Test the platform - // A sharing violation is expected in following code. Otherwise the FileSteam is not implemented correctly. - Assert.ThrowsAny(() => - { - new FileStream(lockFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); - }); - - var task = Task.Run(() => - { - // WorkspaceContext will try to open the lock file for 3 times with 500 ms interval in between. - Thread.Sleep(occupyFileFor); - fs.Dispose(); - }); - - client.Initialize(testProject); - if (expectSuccess) - { - client.DrainMessage(12).AssertDoesNotContain(MessageTypes.Error); - } - else - { - client.DrainTillFirst(MessageTypes.Error); - } - } - } - - [Fact] - public void AddMSBuildReferenceBeforeRestore() - { - var tam = new TestAssetsManager( - Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects")); - - // var appName = "EmptyNetCoreApp"; - var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot; - projectPath = Path.Combine(projectPath, "src", "MainApp"); - - var projectFilePath = Path.Combine(projectPath, Project.FileName); - var projectJson = JsonConvert.DeserializeObject(File.ReadAllText(projectFilePath)); - - ((JObject)projectJson["frameworks"]["net46"]["dependencies"]) - .Add("ClassLibrary4", JToken.FromObject(new { target = "project" })); - - File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - var messages = client.DrainMessage(7); - messages.AssertDoesNotContain(MessageTypes.Error); - messages.RetrieveSingleMessage(MessageTypes.Dependencies) - .RetrieveDependency("ClassLibrary4") - .AssertProperty( - "Version", - v => !string.IsNullOrEmpty(v.ToString()), - v => $"Version string shouldn't be empty. Value [{v.ToString()}]"); - } - } - - [Fact] - public void MSBuildReferenceTest() - { - var testProject = Path.Combine(RepoRoot, "TestAssets", - "ProjectModelServer", - "MSBuildReferencesProjects", - "ValidCase01", - "src", - "MainApp"); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(testProject); - var messages = client.DrainMessage(7); - - var classLibraries = new HashSet(new string[] { "ClassLibrary1", "ClassLibrary2", "ClassLibrary3" }); - var dependencies = messages.RetrieveSingleMessage(MessageTypes.Dependencies); - var testProjectRoot = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects", "ValidCase01"); - foreach (var classLibrary in classLibraries) - { - var dependency = dependencies.RetrieveDependency(classLibrary); - dependency.AssertProperty("Type", LibraryType.MSBuildProject.ToString()); - dependency.AssertProperty("Path", NormalizePathString(Path.Combine(testProjectRoot, classLibrary, $"{classLibrary}.csproj"))); - dependency.AssertProperty("Resolved", true); - dependency.AssertProperty("Name", classLibrary); - dependency.AssertProperty("Errors", array => array.Count == 0); - dependency.AssertProperty("Warnings", array => array.Count == 0); - } - - var references = messages.RetrieveSingleMessage(MessageTypes.References) - .RetrievePayloadAs(); - - var projectReferences = references.RetrievePropertyAs("ProjectReferences"); - Assert.Equal(3, projectReferences.Count); - for (int i = 0; i < 3; ++i) - { - var projectRef = projectReferences.RetrieveArraryElementAs(i); - var name = projectRef["Name"].Value(); - - Assert.True(classLibraries.Contains(name)); - projectRef.AssertProperty("Path", NormalizePathString(Path.Combine(testProjectRoot, name, $"{name}.csproj"))); - } - - var fileReferences = references.RetrievePropertyAs("FileReferences") - .Select(each => each.Value()) - .ToArray(); - foreach (var each in classLibraries) - { - fileReferences.Contains(Path.Combine("ValidCase01", "ClassLibrary1", "bin", "Debug", $"{each}.dll")); - } - } - } - - [Fact] - public void RemovePackageDependencyFromProjectJson() - { - // Remove a package dependency from project.json and then request refreshing dependency before - // restore. - - var appName = "EmptyNetCoreApp"; - var projectPath = _testAssetsManager.CreateTestInstance(appName) - .WithLockFiles() - .TestRoot; - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - - client.DrainMessage(7) - .AssertDoesNotContain(MessageTypes.Error) - .RetrieveSingleMessage(MessageTypes.Dependencies) - .RetrieveDependency(appName) - .RetrievePropertyAs("Dependencies") - .AssertJArrayCount(2); - - var projectFilePath = Path.Combine(projectPath, Project.FileName); - var projectJson = JsonConvert.DeserializeObject(File.ReadAllText(projectFilePath)); - - // Remove newtonsoft.json dependency - var dependencies = projectJson["frameworks"]["netcoreapp1.0"]["dependencies"] as JObject; - dependencies.Remove("Newtonsoft.Json"); - - File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); - - client.SendPayload(projectPath, MessageTypes.RefreshDependencies); - - var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); - afterDependencies.RetrieveDependency(appName) - .RetrievePropertyAs("Dependencies") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("Name", "Microsoft.NETCore.App"); - afterDependencies.RetrieveDependency("Newtonsoft.Json"); - } - } - - [Fact] - public void RemoveMSBuildDependencyFromProjectJson() - { - // Remove a msbuild project dependency from project.json and then request refreshing dependency before - // restore. - - var tam = new TestAssetsManager( - Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects")); - - // var appName = "EmptyNetCoreApp"; - var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot; - projectPath = Path.Combine(projectPath, "src", "MainApp"); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - - client.DrainMessage(7) - .AssertDoesNotContain(MessageTypes.Error) - .RetrieveSingleMessage(MessageTypes.Dependencies) - .RetrieveDependency("MainApp") - .RetrievePropertyAs("Dependencies") - .AssertJArrayContains(dep => dep["Name"].Value() == "ClassLibrary1") - .AssertJArrayContains(dep => dep["Name"].Value() == "ClassLibrary2") - .AssertJArrayContains(dep => dep["Name"].Value() == "ClassLibrary3"); - - var projectFilePath = Path.Combine(projectPath, Project.FileName); - var projectJson = JsonConvert.DeserializeObject(File.ReadAllText(projectFilePath)); - - // Remove ClassLibrary2 and ClassLibrary3 dependency - var dependencies = projectJson["frameworks"]["net46"]["dependencies"] as JObject; - dependencies.Remove("ClassLibrary2"); - dependencies.Remove("ClassLibrary3"); - - File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); - - client.SendPayload(projectPath, MessageTypes.RefreshDependencies); - - var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); - afterDependencies.RetrieveDependency("MainApp") - .RetrievePropertyAs("Dependencies") - .AssertJArrayNotContains(dep => dep["Name"].Value() == "ClassLibrary2") - .AssertJArrayNotContains(dep => dep["Name"].Value() == "ClassLibrary3"); - - afterDependencies.RetrieveDependency("ClassLibrary2"); - afterDependencies.RetrieveDependency("ClassLibrary3"); - } - } - - [Fact] - public void TestMscorlibLibraryDuplication() - { - var projectPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MscorlibLibraryDuplication"); - - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - client.Initialize(projectPath); - client.DrainMessage(7).AssertDoesNotContain(MessageTypes.Error); - } - } - - [Fact] - public void TestTargetFrameworkChange() - { - using (var server = new DthTestServer()) - using (var client = new DthTestClient(server)) - { - var testProject = _testAssetsManager.CreateTestInstance("EmptyLibrary") - .WithLockFiles() - .TestRoot; - - // initialize the project and drain all messages (7 message for project with one framework) - client.Initialize(testProject); - client.DrainMessage(7); - - // update the target framework from netstandard1.3 to netstandard 1.5 so as to invalidate all - // dependencies - var projectJsonPath = Path.Combine(testProject, "project.json"); - File.WriteAllText(projectJsonPath, - File.ReadAllText(projectJsonPath).Replace("netstandard1.3", "netstandard1.5")); - - // send files change request to server to prompt update - client.SendPayload(testProject, MessageTypes.FilesChanged); - - // assert project information is updated - client.DrainTillFirst(MessageTypes.ProjectInformation) - .RetrievePayloadAs() - .RetrievePropertyAs("Frameworks") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("ShortName", "netstandard1.5"); - - // the NETStandard.Library dependency should turn unresolved - var dependencies = client.DrainTillFirst(MessageTypes.Dependencies); - - dependencies.RetrievePayloadAs() - .RetrievePropertyAs("Framework") - .AssertProperty("ShortName", "netstandard1.5"); - - dependencies.RetrieveDependency("NETStandard.Library") - .RetrievePropertyAs("Errors") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("ErrorCode", "NU1001"); - - // warning for project.json and project.lock.json out of sync - var diagnostics = client.DrainTillFirst(MessageTypes.DependencyDiagnostics); - - diagnostics.RetrievePayloadAs() - .RetrievePropertyAs("Framework") - .AssertProperty("ShortName", "netstandard1.5"); - - diagnostics.RetrievePayloadAs() - .RetrievePropertyAs("Warnings") - .AssertJArrayCount(1) - .RetrieveArraryElementAs(0) - .AssertProperty("ErrorCode", "NU1006"); - - // restore again - var restoreCommand = new RestoreCommand(); - restoreCommand.WorkingDirectory = testProject; - restoreCommand.Execute().Should().Pass(); - - client.SendPayload(testProject, MessageTypes.RefreshDependencies); - - client.DrainTillFirst(MessageTypes.Dependencies) - .RetrieveDependency("NETStandard.Library") - .RetrievePropertyAs("Errors") - .AssertJArrayCount(0); - - client.DrainTillFirst(MessageTypes.DependencyDiagnostics) - .RetrievePayloadAs() - .RetrievePropertyAs("Warnings") - .AssertJArrayCount(0); - } - } - - private static string NormalizePathString(string original) - { - return original.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); - } - - private static void PrintAllMessages(IEnumerable messages) - { - foreach (var message in messages) - { - Console.WriteLine($"{message.MessageType} => {message.Payload.ToString()}"); - } - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessage.cs b/test/dotnet-projectmodel-server.Tests/Helpers/DthMessage.cs deleted file mode 100644 index b0360d6b3..000000000 --- a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessage.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public class DthMessage - { - public string HostId { get; set; } - - public string MessageType { get; set; } - - public int ContextId { get; set; } - - public int Version { get; set; } - - public JToken Payload { get; set; } - - // for ProjectContexts message only - public Dictionary Projects { get; set; } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageCollectionExtension.cs b/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageCollectionExtension.cs deleted file mode 100644 index 4a8545c28..000000000 --- a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageCollectionExtension.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Versioning; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public static class DthMessageCollectionExtension - { - public static IList GetMessagesByFramework(this IEnumerable messages, FrameworkName targetFramework) - { - return messages.Where(msg => MatchesFramework(targetFramework, msg)).ToList(); - } - - public static IList GetMessagesByType(this IEnumerable messages, string typename) - { - return messages.Where(msg => string.Equals(msg.MessageType, typename)).ToList(); - } - - public static DthMessage RetrieveSingleMessage(this IEnumerable messages, - string typename) - { - var result = messages.SingleOrDefault(msg => string.Equals(msg.MessageType, typename, StringComparison.Ordinal)); - - if (result == null) - { - if (messages.FirstOrDefault(msg => string.Equals(msg.MessageType, typename, StringComparison.Ordinal)) != null) - { - Assert.False(true, $"More than one {typename} messages exist."); - } - else - { - Assert.False(true, $"{typename} message doesn't exists."); - } - } - - return result; - } - - public static IEnumerable ContainsMessage(this IEnumerable messages, - string typename) - { - var contain = messages.FirstOrDefault(msg => string.Equals(msg.MessageType, typename, StringComparison.Ordinal)) != null; - - Assert.True(contain, $"Messages collection doesn't contain message of type {typename}."); - - return messages; - } - - public static IEnumerable AssertDoesNotContain(this IEnumerable messages, string typename) - { - var notContain = messages.FirstOrDefault(msg => string.Equals(msg.MessageType, typename, StringComparison.Ordinal)) == null; - - Assert.True(notContain, $"Message collection contains message of type {typename}."); - - return messages; - } - - private static bool MatchesFramework(FrameworkName targetFramework, DthMessage msg) - { - if (msg.Payload.Type != JTokenType.Object) - { - return false; - } - - var frameworkObj = msg.Payload["Framework"]; - - if (frameworkObj == null || !frameworkObj.HasValues) - { - return false; - } - - return string.Equals(frameworkObj.Value("FrameworkName"), targetFramework.FullName, StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageExtension.cs b/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageExtension.cs deleted file mode 100644 index 6230884c9..000000000 --- a/test/dotnet-projectmodel-server.Tests/Helpers/DthMessageExtension.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public static class DthMessageExtension - { - public static JObject RetrieveDependency(this DthMessage message, string dependencyName) - { - Assert.NotNull(message); - Assert.Equal(MessageTypes.Dependencies, message.MessageType); - - var payload = message.Payload as JObject; - Assert.NotNull(payload); - - var dependency = payload[MessageTypes.Dependencies][dependencyName] as JObject; - Assert.NotNull(dependency); - Assert.Equal(dependencyName, dependency["Name"].Value()); - - return dependency; - } - - public static DthMessage EnsureNotContainDependency(this DthMessage message, string dependencyName) - { - Assert.NotNull(message); - Assert.Equal(MessageTypes.Dependencies, message.MessageType); - - var payload = message.Payload as JObject; - Assert.NotNull(payload); - - Assert.True(payload[MessageTypes.Dependencies][dependencyName] == null, $"Unexpected dependency {dependencyName} exists."); - - return message; - } - - public static JObject RetrieveDependencyDiagnosticsCollection(this DthMessage message) - { - Assert.NotNull(message); - Assert.Equal(MessageTypes.DependencyDiagnostics, message.MessageType); - - var payload = message.Payload as JObject; - Assert.NotNull(payload); - - return payload; - } - - public static T RetrievePayloadAs(this DthMessage message) - where T : JToken - { - Assert.NotNull(message); - AssertType(message.Payload, "Payload"); - - return (T)message.Payload; - } - - /// - /// Throws if the message is not generated in communication between given server and client - /// - public static DthMessage EnsureSource(this DthMessage message, DthTestServer server, DthTestClient client) - { - if (message.HostId != server.HostId) - { - throw new Exception($"{nameof(message.HostId)} doesn't match the one of server. Expected {server.HostId} but actually {message.HostId}."); - } - - return message; - } - - public static void AssertType(object obj, string name) - { - Assert.True(obj is T, $"{name} is not of type {typeof(T).Name}."); - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/Helpers/JArrayExtensions.cs b/test/dotnet-projectmodel-server.Tests/Helpers/JArrayExtensions.cs deleted file mode 100644 index fb925fe72..000000000 --- a/test/dotnet-projectmodel-server.Tests/Helpers/JArrayExtensions.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public static class JArrayExtensions - { - public static JArray AssertJArrayEmpty(this JArray array) - { - Assert.NotNull(array); - Assert.Empty(array); - - return array; - } - - public static JArray AssertJArrayNotEmpty(this JArray array) - { - Assert.NotNull(array); - Assert.NotEmpty(array); - - return array; - } - - public static JArray AssertJArrayCount(this JArray array, int expectedCount) - { - Assert.NotNull(array); - Assert.Equal(expectedCount, array.Count); - - return array; - } - - public static JArray AssertJArrayElement(this JArray array, int index, T expectedElementValue) - { - Assert.NotNull(array); - - var element = array[index]; - Assert.NotNull(element); - Assert.Equal(expectedElementValue, element.Value()); - - return array; - } - - public static JArray AssertJArrayContains(this JArray array, T value) - { - AssertJArrayContains(array, element => object.Equals(element, value)); - - return array; - } - - public static JArray AssertJArrayContains(this JArray array, Func critiera) - { - bool contains = false; - foreach (var element in array) - { - var value = element.Value(); - - contains = critiera(value); - if (contains) - { - break; - } - } - - Assert.True(contains, "JArray doesn't contains the specified element."); - - return array; - } - - public static JArray AssertJArrayNotContains(this JArray array, Func critiera) - { - foreach (var element in array) - { - var value = element.Value(); - - if (critiera(value)) - { - Assert.True(false, "JArray contains unexpected element."); - } - } - - return array; - } - - public static T RetrieveArraryElementAs(this JArray json, int index) - where T : JToken - { - Assert.NotNull(json); - Assert.True(index >= 0 && index < json.Count, "Index out of range"); - - var element = json[index]; - DthMessageExtension.AssertType(element, $"Element at {index}"); - - return (T)element; - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/Helpers/JObjectExtensions.cs b/test/dotnet-projectmodel-server.Tests/Helpers/JObjectExtensions.cs deleted file mode 100644 index aa513917c..000000000 --- a/test/dotnet-projectmodel-server.Tests/Helpers/JObjectExtensions.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Server.Tests -{ - public static class JObjectExtensions - { - public static JObject AsJObject(this JToken token) - { - DthMessageExtension.AssertType(token, nameof(JToken)); - - return (JObject)token; - } - - public static JObject RetrieveDependencyDiagnosticsErrorAt(this JObject payload, int index) - { - Assert.NotNull(payload); - - return payload.RetrievePropertyAs("Errors") - .RetrieveArraryElementAs(index); - } - - public static T RetrieveDependencyDiagnosticsErrorAt(this JObject payload, int index) - where T : JToken - { - Assert.NotNull(payload); - - return payload.RetrievePropertyAs("Errors") - .RetrieveArraryElementAs(index); - } - - public static T RetrievePropertyAs(this JObject json, string propertyName) - where T : JToken - { - Assert.NotNull(json); - - var property = json[propertyName]; - Assert.NotNull(property); - DthMessageExtension.AssertType(property, $"Property {propertyName}"); - - return (T)property; - } - - public static JObject AssertProperty(this JObject json, string propertyName, T expectedPropertyValue) - { - Assert.NotNull(json); - - var property = json[propertyName]; - Assert.NotNull(property); - Assert.Equal(expectedPropertyValue, property.Value()); - - return json; - } - - public static JObject AssertProperty(this JObject json, string propertyName, Func assertion) - { - return AssertProperty(json, - propertyName, - assertion, - value => $"Assert failed on {propertyName}."); - } - - public static JObject AssertProperty(this JObject json, string propertyName, Func assertion, Func errorMessage) - { - Assert.NotNull(json); - - var property = json[propertyName]; - Assert.False(property == null, $"Property {propertyName} doesn't exist."); - - var propertyValue = property.Value(); - Assert.False(propertyValue == null, $"Property {propertyName} of type {typeof(T).Name} doesn't exist."); - - Assert.True(assertion(propertyValue), - errorMessage(propertyValue)); - - return json; - } - } -} diff --git a/test/dotnet-projectmodel-server.Tests/dotnet-projectmodel-server.Tests.xproj b/test/dotnet-projectmodel-server.Tests/dotnet-projectmodel-server.Tests.xproj deleted file mode 100644 index 29f474eb4..000000000 --- a/test/dotnet-projectmodel-server.Tests/dotnet-projectmodel-server.Tests.xproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 11c77123-e4da-499f-8900-80c88c2c69f2 - Microsoft.DotNet.ProjectModel.Server.Tests - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/dotnet-projectmodel-server.Tests/project.json b/test/dotnet-projectmodel-server.Tests/project.json deleted file mode 100644 index c75556768..000000000 --- a/test/dotnet-projectmodel-server.Tests/project.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet": { - "target": "project" - }, - "Microsoft.Win32.Registry": { - "version": "4.0.0", - "exclude": "Compile" - }, - "Microsoft.DotNet.Tools.Tests.Utilities": { - "target": "project" - }, - "Microsoft.DotNet.ProjectModel": { - "target": "project" - }, - "xunit": "2.1.0", - "dotnet-test-xunit": "1.0.0-rc2-192208-24", - "System.Net.NameResolution": "4.0.0" - }, - "frameworks": { - "netcoreapp1.0": { - "imports": [ - "netstandardapp1.5", - "dotnet5.4", - "portable-net451+win8" - ] - } - }, - "testRunner": "xunit" -}