From fa2c0f8541ed96a303927131abe268952bf37706 Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Wed, 29 Mar 2017 16:37:11 -0700 Subject: [PATCH 1/5] Enable RuntimeInformation intrinsic funcitons on all platforms --- dir.props | 1 - .../Evaluation/Expander_Tests.cs | 42 ++++++++++++------- src/Build/Resources/Constants.cs | 4 -- src/Build/project.json | 3 ++ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/dir.props b/dir.props index e35c8dbcae0..6eb737bb0eb 100644 --- a/dir.props +++ b/dir.props @@ -368,7 +368,6 @@ $(DefineConstants);FEATURE_CULTUREINFO_SETTERS $(DefineConstants);FEATURE_PROCESSSTARTINFO_ENVIRONMENT - $(DefineConstants);FEATURE_RUNTIMEINFORMATION $(DefineConstants);USE_MSBUILD_DLL_EXTN diff --git a/src/Build.UnitTests/Evaluation/Expander_Tests.cs b/src/Build.UnitTests/Evaluation/Expander_Tests.cs index 56c394fd89c..b320ed5cf2e 100644 --- a/src/Build.UnitTests/Evaluation/Expander_Tests.cs +++ b/src/Build.UnitTests/Evaluation/Expander_Tests.cs @@ -2565,19 +2565,32 @@ public void PropertyFunctionGetFolderPath() } #endif -#if FEATURE_RUNTIMEINFORMATION /// - /// Expand property function that uses types available only on .netstandard1.3 and above (RuntimeInformation) - /// The test exercises: static method invocation, static property invocation, method invocation expression as argument, call chain expression as argument, - /// - [Fact] - public void PropertyFunctionRuntimeInformation() - { - var pg = new PropertyDictionary(); + /// The test exercises: RuntimeInformation / OSPlatform usage, static method invocation, static property invocation, method invocation expression as argument, call chain expression as argument + /// + [Theory] + [InlineData( + "$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Create($([System.Runtime.InteropServices.OSPlatform]::$$platform$$.ToString())))))", + "True" + )] + [InlineData( + @"$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::$$platform$$)))", + "True" + )] + [InlineData( + "$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)", + "$$architecture$$" + )] + public void PropertyFunctionRuntimeInformation(string propertyFunction, string expectedExpansion) + { + Func formatString = (aString, platform, architecture) => aString + .Replace("$$platform$$", platform) + .Replace("$$architecture$$", architecture); + var pg = new PropertyDictionary(); var expander = new Expander(pg); - var currentPlatformString = ""; + var currentPlatformString = string.Empty; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -2592,16 +2605,15 @@ public void PropertyFunctionRuntimeInformation() currentPlatformString = "OSX"; } - var propertyFunction = "$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(" + - "$([System.Runtime.InteropServices.OSPlatform]::Create(" + - $"$([System.Runtime.InteropServices.OSPlatform]::{currentPlatformString}.ToString()" + - ")))))"; + var currentArchitectureString = RuntimeInformation.OSArchitecture.ToString(); + + propertyFunction = formatString(propertyFunction, currentPlatformString, currentArchitectureString); + expectedExpansion = formatString(expectedExpansion, currentPlatformString, currentArchitectureString); var result = expander.ExpandIntoStringLeaveEscaped(propertyFunction, ExpanderOptions.ExpandProperties, MockElementLocation.Instance); - Assert.Equal("True", result); + Assert.Equal(expectedExpansion, result); } -#endif /// /// Expand property function that calls a method with an enum parameter diff --git a/src/Build/Resources/Constants.cs b/src/Build/Resources/Constants.cs index e39816cbbb1..b805aee2d0a 100644 --- a/src/Build/Resources/Constants.cs +++ b/src/Build/Resources/Constants.cs @@ -326,10 +326,8 @@ private static void InitializeAvailableMethods() var environmentType = new Tuple(null, typeof(System.Environment)); var directoryType = new Tuple(null, typeof(System.IO.Directory)); var fileType = new Tuple(null, typeof(System.IO.File)); -#if FEATURE_RUNTIMEINFORMATION var runtimeInformationType = new Tuple(null, typeof(System.Runtime.InteropServices.RuntimeInformation)); var osPlatformType = new Tuple(null, typeof(System.Runtime.InteropServices.OSPlatform)); -#endif // Make specific static methods available (Assembly qualified type names are *NOT* supported, only null which means mscorlib): TryAdd("System.Environment::ExpandEnvironmentVariables", environmentType); @@ -421,10 +419,8 @@ private static void InitializeAvailableMethods() TryAdd("System.UriBuilder", new Tuple(null, typeof(System.UriBuilder))); TryAdd("System.Version", new Tuple(null, typeof(System.Version))); TryAdd("Microsoft.Build.Utilities.ToolLocationHelper", new Tuple("Microsoft.Build.Utilities.ToolLocationHelper, Microsoft.Build.Utilities.Core, Version=" + MSBuildConstants.CurrentAssemblyVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null)); -#if FEATURE_RUNTIMEINFORMATION TryAdd("System.Runtime.InteropServices.RuntimeInformation", runtimeInformationType); TryAdd("System.Runtime.InteropServices.OSPlatform", osPlatformType); -#endif } } } diff --git a/src/Build/project.json b/src/Build/project.json index 3dcb1979bf3..3c04b31287d 100644 --- a/src/Build/project.json +++ b/src/Build/project.json @@ -1,4 +1,7 @@ { + "dependencies": { + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0" + }, "frameworks": { "net46": { "dependencies": { From 609f33227a8edc25ea5b5bc16e16362e884aa6b7 Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Thu, 30 Mar 2017 11:16:42 -0700 Subject: [PATCH 2/5] Copy RuntimeInformation nuget dependency over to output --- setup/files.swr | 2 ++ src/Build/Microsoft.Build.csproj | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/setup/files.swr b/setup/files.swr index 3238c7f4c70..b366430fd36 100644 --- a/setup/files.swr +++ b/setup/files.swr @@ -22,6 +22,7 @@ folder InstallDir:\MSBuild\15.0\Bin file source=$(X86BinPath)MSBuildTaskHost.exe.config file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngenArchitecture=all file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngenArchitecture=all + file source=$(X86BinPath)System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngenArchitecture=all file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets file source=$(X86BinPath)Microsoft.Common.overridetasks @@ -149,6 +150,7 @@ folder InstallDir:\MSBuild\15.0\Bin\amd64 file source=$(X86BinPath)Microsoft.Build.Utilities.Core.dll vs.file.ngenArchitecture=all file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngenArchitecture=all file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngenArchitecture=all + file source=$(X86BinPath)System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngenArchitecture=all file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets file source=$(X86BinPath)Microsoft.Common.overridetasks diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index 3545d2dae80..e41c4befcc1 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -785,9 +785,10 @@ --> - - - + true From 979bf8cec2a67a57aa084e43a8745e8c67134f50 Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Fri, 31 Mar 2017 13:07:46 -0700 Subject: [PATCH 3/5] Propagate dependencies for consistency and explicitness --- build/NuGetPackages/Microsoft.Build.Runtime.nuspec | 2 ++ build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec | 1 + build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec | 1 + build/NuGetPackages/Microsoft.Build.nuspec | 1 + src/MSBuild/project.json | 3 +++ src/Tasks/project.json | 3 +++ src/Utilities/project.json | 3 +++ targets/runtimeDependencies/project.json | 5 ++--- 8 files changed, 16 insertions(+), 3 deletions(-) diff --git a/build/NuGetPackages/Microsoft.Build.Runtime.nuspec b/build/NuGetPackages/Microsoft.Build.Runtime.nuspec index 67f2f319a06..79ba7f67f82 100644 --- a/build/NuGetPackages/Microsoft.Build.Runtime.nuspec +++ b/build/NuGetPackages/Microsoft.Build.Runtime.nuspec @@ -19,12 +19,14 @@ + + diff --git a/build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec b/build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec index ef1edc4d25e..e3a29d2613f 100644 --- a/build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec +++ b/build/NuGetPackages/Microsoft.Build.Tasks.Core.nuspec @@ -67,6 +67,7 @@ + diff --git a/build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec b/build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec index 96e41e8e025..2c50daa6651 100644 --- a/build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec +++ b/build/NuGetPackages/Microsoft.Build.Utilities.Core.nuspec @@ -53,6 +53,7 @@ + diff --git a/build/NuGetPackages/Microsoft.Build.nuspec b/build/NuGetPackages/Microsoft.Build.nuspec index 6f5582fb72a..22c95e241a4 100644 --- a/build/NuGetPackages/Microsoft.Build.nuspec +++ b/build/NuGetPackages/Microsoft.Build.nuspec @@ -64,6 +64,7 @@ + diff --git a/src/MSBuild/project.json b/src/MSBuild/project.json index dd84573b319..7d861f221f4 100644 --- a/src/MSBuild/project.json +++ b/src/MSBuild/project.json @@ -1,4 +1,7 @@ { + "dependencies": { + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0" + }, "frameworks": { "net46": { "dependencies": { diff --git a/src/Tasks/project.json b/src/Tasks/project.json index defda8d2ee5..11a34e67620 100644 --- a/src/Tasks/project.json +++ b/src/Tasks/project.json @@ -1,4 +1,7 @@ { + "dependencies": { + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0" + }, "frameworks": { "net46": { "dependencies": { diff --git a/src/Utilities/project.json b/src/Utilities/project.json index a8fa80caf38..24fd438fbcb 100644 --- a/src/Utilities/project.json +++ b/src/Utilities/project.json @@ -1,4 +1,7 @@ { + "dependencies": { + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0" + }, "frameworks": { "net46": { "dependencies": { diff --git a/targets/runtimeDependencies/project.json b/targets/runtimeDependencies/project.json index f94600b3cca..58d0b341daa 100644 --- a/targets/runtimeDependencies/project.json +++ b/targets/runtimeDependencies/project.json @@ -11,14 +11,14 @@ "xunit": "2.1.0", "microsoft.xunit.netcore.extensions": "1.0.0-prerelease-00629-09", "System.IO.FileSystem": "4.0.1", - "System.IO.Compression": "4.1.0" + "System.IO.Compression": "4.1.0", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0" }, "frameworks": { "net46": { "dependencies": { "xunit.runner.visualstudio": "2.1.0", "System.Collections.Immutable": "1.3.1", - "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", "System.Threading.Tasks.Dataflow": "4.5.24.0", "Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00508-01" } @@ -32,7 +32,6 @@ "Microsoft.NETCore.Platforms": "1.0.1", "System.Collections.NonGeneric": "4.0.1", "System.Console": "4.0.0", - "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", "System.IO.FileSystem.Watcher": "4.0.0", "System.IO.FileSystem.DriveInfo": "4.0.0", "System.IO.Pipes": "4.0.0", From 351a3551651da0a3df621448351f74b0331aeb0b Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Fri, 31 Mar 2017 13:18:37 -0700 Subject: [PATCH 4/5] Move copy local copying to DeployRuntime The Reference items produced by ResolveNugetPackages target during project builds are either reference assemblies or real assemblies. Therefore they are not a good source for copying into the output directory, as copied reference assemblies would crash at runtime. Move the copying in the DeployDependencies project file because the DeployRuntime target in there uses the real assemblies. This should all be removed whenever we move to dotnet publish --- src/Build/Microsoft.Build.csproj | 19 ---------------- targets/DeployDependencies.proj | 37 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index e41c4befcc1..4ec2fb7daea 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -785,23 +785,4 @@ --> - - - - - true - - - \ No newline at end of file diff --git a/targets/DeployDependencies.proj b/targets/DeployDependencies.proj index 762e74355c5..19d491d8a04 100644 --- a/targets/DeployDependencies.proj +++ b/targets/DeployDependencies.proj @@ -110,7 +110,7 @@ - + + + + + + + + + Date: Fri, 31 Mar 2017 15:34:00 -0700 Subject: [PATCH 5/5] remove dependency from runtime nuspec --- build/NuGetPackages/Microsoft.Build.Runtime.nuspec | 2 -- 1 file changed, 2 deletions(-) diff --git a/build/NuGetPackages/Microsoft.Build.Runtime.nuspec b/build/NuGetPackages/Microsoft.Build.Runtime.nuspec index 79ba7f67f82..67f2f319a06 100644 --- a/build/NuGetPackages/Microsoft.Build.Runtime.nuspec +++ b/build/NuGetPackages/Microsoft.Build.Runtime.nuspec @@ -19,14 +19,12 @@ - -