Skip to content

Commit

Permalink
Target netcoreapp1.0 for MSBuild executable (dotnet#1137)
Browse files Browse the repository at this point in the history
* Target netcoreapp1.0 for MSBuild executable

* Rename MSBuild.exe to MSBuild.dll when building netcore
  • Loading branch information
jeffkl authored Oct 11, 2016
1 parent d5e1e8e commit c4cdc08
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Before.Microsoft.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--
This property is already defined in the root dir.props however importing Microsoft.Portable.CSharp.targets will
override it. If you change it here, update it in the root dir.props as well. -->
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_TargetFrameworkIdentifierBackup)' != '' ">$(_TargetFrameworkIdentifierBackup)</TargetFrameworkIdentifier>
<!-- This property needs to be cleared -->
<TargetFrameworkMonikerDisplayName></TargetFrameworkMonikerDisplayName>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion build/NuGetPackages/Microsoft.Build.Runtime.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
<!--
contentFiles\any\netcoreapp1.0
-->
<file src="$configuration$-NetCore\Output\MSBuild.exe" target="contentFiles\any\netcoreapp1.0\" />
<file src="$configuration$-NetCore\Output\MSBuild.dll" target="contentFiles\any\netcoreapp1.0\" />
<file src="$configuration$-NetCore\Output\MSBuild.runtimeconfig.json" target="contentFiles\any\netcoreapp1.0\" />
<file src="$configuration$-NetCore\Output\Microsoft.Common.CrossTargeting.targets" target="contentFiles\any\netcoreapp1.0\" />
<file src="$configuration$-NetCore\Output\Microsoft.Common.CurrentVersion.targets" target="contentFiles\any\netcoreapp1.0\" />
<file src="$configuration$-NetCore\Output\Microsoft.Common.overridetasks" target="contentFiles\any\netcoreapp1.0\" />
Expand Down
2 changes: 1 addition & 1 deletion cibuild.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if /i "%TARGET%"=="CoreCLR" (
)

if /i "%TARGET%"=="CoreCLR" (
set MSBUILD_CUSTOM_PATH="%~dp0bin\Bootstrap\MSBuild.exe"
set MSBUILD_CUSTOM_PATH="%~dp0bin\Bootstrap\MSBuild.dll"
) else (
set MSBUILD_CUSTOM_PATH="%~dp0bin\Bootstrap\15.0\Bin\MSBuild.exe"
)
Expand Down
2 changes: 1 addition & 1 deletion cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ MOVE_LOG_PATH="$THIS_SCRIPT_PATH"/"msbuild_move_bootstrap.log"
PROJECT_FILE_ARG='"'"$THIS_SCRIPT_PATH/build.proj"'"'
BOOTSTRAP_FILE_ARG='"'"$THIS_SCRIPT_PATH/BootStrapMSBuild.proj"'"'
BOOTSTRAPPED_RUNTIME_HOST='"'"$THIS_SCRIPT_PATH/bin/Bootstrap/dotnet"'"'
MSBUILD_BOOTSTRAPPED_EXE='"'"$THIS_SCRIPT_PATH/bin/Bootstrap/MSBuild.exe"'"'
MSBUILD_BOOTSTRAPPED_EXE='"'"$THIS_SCRIPT_PATH/bin/Bootstrap/MSBuild.dll"'"'

# Default msbuild arguments
TARGET_ARG="Build"
Expand Down
10 changes: 7 additions & 3 deletions dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<ToolPackagesDir>$(RepoRoot)packages$([System.IO.Path]::DirectorySeparatorChar)</ToolPackagesDir>
<MicroBuildDir>$(ToolPackagesDir)\MicroBuild.Core\$(MicroBuildVersion)\build\</MicroBuildDir>
<GitVersioningDir>$(PackagesDir)\Nerdbank.GitVersioning\$(GitVersioningVersion)\build\</GitVersioningDir>

<!-- Tell build tools to use the full framework dlls that contain build tasks (like the nuget assets task) -->
<BuildToolsTaskDir>$(ToolsDir)net45/</BuildToolsTaskDir>
<PackagingTaskDir>$(ToolsDir)net45/</PackagingTaskDir>
Expand Down Expand Up @@ -224,7 +224,11 @@
<!--
This property is re-created after importing Microsoft.Portable.CSharp.targets. If you change the value here, also
update it in Before.Microsoft.Common.targets -->
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETStandard</TargetFrameworkIdentifier>
<!--
Backup $(TargetFrameworkIdentifier) because it will be statically set by Microsoft.CSharp.Portable.targets and reset in our Before.Microsoft.Common.targets
-->
<_TargetFrameworkIdentifierBackup Condition="'$(TargetFrameworkIdentifier)' != ''">$(TargetFrameworkIdentifier)</_TargetFrameworkIdentifierBackup>
<NetCoreSurface>true</NetCoreSurface>

<!-- Setting this to false stops the AppX targets, which aren't supported on .NET Core, from beeing imported -->
Expand All @@ -240,7 +244,7 @@
<PropertyGroup>
<PlatformTarget>$(RuntimeArchitecture)</PlatformTarget>
<ImportGetNuGetPackageVersions Condition="'$(OS)' != 'Windows_NT'">false</ImportGetNuGetPackageVersions>
<NuGetTargetMoniker Condition="'$(NetCoreBuild)' == 'true'">.NETStandard,Version=$(TargetFrameworkVersion)</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(NetCoreBuild)' == 'true'">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(NetCoreBuild)' != 'true'">.NETFramework,Version=$(TargetFrameworkVersion)</NuGetTargetMoniker>
</PropertyGroup>

Expand Down
17 changes: 11 additions & 6 deletions src/Shared/BuildEnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ internal class BuildEnvironmentHelper
/// </summary>
private static readonly string[] s_msBuildProcess = {"MSBUILD"};

/// <summary>
/// Name of MSBuild executable files.
/// </summary>
private static readonly string[] s_msBuildExeNames = {"MSBuild.exe", "MSBuild.dll"};

/// <summary>
/// Gets the cached Build Environment instance.
/// </summary>
Expand Down Expand Up @@ -123,11 +128,11 @@ private static BuildEnvironment TryFromFolder(string folder, bool runningTests,
{
if (string.IsNullOrEmpty(folder)) return null;

var msBuildPath = Path.Combine(folder, "MSBuild.exe");

return IsValidMSBuildPath(msBuildPath)
? new BuildEnvironment(msBuildPath, runningTests, runningInVisualStudio, visualStudioPath)
: null;
return (
s_msBuildExeNames.Select(msbuildFileName => Path.Combine(folder, msbuildFileName))
.Where(IsValidMSBuildPath)
.Select(msBuildPath => new BuildEnvironment(msBuildPath, runningTests, runningInVisualStudio, visualStudioPath))
).FirstOrDefault();
}

/// <summary>
Expand All @@ -143,7 +148,7 @@ private static BuildEnvironment TryFromFolder(string folder, bool runningTests,
private static bool IsValidMSBuildPath(string path)
{
bool msbuildExeExists = !string.IsNullOrEmpty(path) &&
Path.GetFileName(path).Equals("MSBuild.exe", StringComparison.OrdinalIgnoreCase) &&
s_msBuildExeNames.Any(i => i.Equals(Path.GetFileName(path), StringComparison.OrdinalIgnoreCase)) &&
File.Exists(path);
#if FEATURE_SYSTEM_CONFIGURATION
// If we can read toolsets out of msbuild.exe.config, we must
Expand Down
12 changes: 9 additions & 3 deletions src/Utilities/UnitTests/ToolLocationHelper_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ sealed public class ToolLocationHelper_Tests
{
private readonly ITestOutputHelper _output;

#if FEATURE_RUN_EXE_IN_TESTS
private const string MSBuildExeName = "MSBuild.exe";
#else
private const string MSBuildExeName = "MSBuild.dll";
#endif

public ToolLocationHelper_Tests(ITestOutputHelper output)
{
_output = output;
Expand Down Expand Up @@ -591,10 +597,10 @@ public void TestGetPathToBuildToolsFile()
ToolLocationHelper.GetPathToBuildToolsFile("MSBuild.exe", "4.0")
);

string tv12path = Path.Combine(ProjectCollection.GlobalProjectCollection.GetToolset(ObjectModelHelpers.MSBuildDefaultToolsVersion).ToolsPath, "MSBuild.exe");
string tv12path = Path.Combine(ProjectCollection.GlobalProjectCollection.GetToolset(ObjectModelHelpers.MSBuildDefaultToolsVersion).ToolsPath, MSBuildExeName);

Assert.Equal(tv12path, ToolLocationHelper.GetPathToBuildToolsFile("MSBuild.exe", ObjectModelHelpers.MSBuildDefaultToolsVersion));
Assert.Equal(tv12path, ToolLocationHelper.GetPathToBuildToolsFile("MSBuild.exe", ToolLocationHelper.CurrentToolsVersion));
Assert.Equal(tv12path, ToolLocationHelper.GetPathToBuildToolsFile(MSBuildExeName, ObjectModelHelpers.MSBuildDefaultToolsVersion));
Assert.Equal(tv12path, ToolLocationHelper.GetPathToBuildToolsFile(MSBuildExeName, ToolLocationHelper.CurrentToolsVersion));
}

#if RUNTIME_TYPE_NETCORE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace Microsoft.Build.Engine.UnitTests
{
public class BuildEnvironmentHelper_Tests
{
#if FEATURE_RUN_EXE_IN_TESTS
private const string MSBuildExeName = "MSBuild.exe";
#else
private const string MSBuildExeName = "MSBuild.dll";
#endif
[Fact]
public void GetExecutablePath()
{
Expand All @@ -22,7 +27,7 @@ public void GetExecutablePath()
var msbuildPath = Path.GetDirectoryName(AssemblyUtilities.GetAssemblyLocation(typeof(Project).GetTypeInfo().Assembly));
Directory.SetCurrentDirectory(msbuildPath);

string path = Path.Combine(Directory.GetCurrentDirectory(), "msbuild.exe").ToLowerInvariant();
string path = Path.Combine(Directory.GetCurrentDirectory(), MSBuildExeName).ToLowerInvariant();
string configPath = BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile.ToLowerInvariant();
string directoryName = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.ToLowerInvariant();
string executablePath = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath.ToLowerInvariant();
Expand Down
24 changes: 22 additions & 2 deletions src/XMakeCommandLine/MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PlatformSpecificBuild>true</PlatformSpecificBuild>
<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == '' and ('$(Configuration)' == 'Debug-NetCore' or '$(Configuration)' == 'Release-NetCore')">v1.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug-NetCore' or '$(Configuration)' == 'Release-NetCore'">
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<NoStdLib>true</NoStdLib>
<NoWarn>$(NoWarn);1701</NoWarn>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
Expand Down Expand Up @@ -211,7 +217,9 @@
<Content Include="MSBuild.rsp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

<Content Include="MSBuild.runtimeconfig.json" Condition="'$(NetCoreBuild)' == 'true'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Microsoft.Build.CommonTypes.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down Expand Up @@ -249,4 +257,16 @@
<None Include="project.json" />
</ItemGroup>
<Import Project="..\dir.targets" />
<PropertyGroup Condition="'$(NetCoreBuild)' == 'true'">
<!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two
properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and
to prevent it from outputting a warning (MSB3644).
-->
<_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>
<_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>

<!-- MSBuild thinks all EXEs need binding redirects, not so for CoreCLR! -->
<AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions src/XMakeCommandLine/MSBuild.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "1.0.1"
}
}
}
22 changes: 14 additions & 8 deletions src/XMakeCommandLine/UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ namespace Microsoft.Build.UnitTests
{
public class XMakeAppTests
{
#if FEATURE_RUN_EXE_IN_TESTS
private const string MSBuildExeName = "MSBuild.exe";
#else
private const string MSBuildExeName = "MSBuild.dll";
#endif

[Fact]
public void GatherCommandLineSwitchesTwoProperties()
{
Expand Down Expand Up @@ -1028,7 +1034,7 @@ public void ResponseFileInProjectDirectoryWinsOverMainMSBuildRsp()
string rspPath = Path.Combine(directory, "msbuild.rsp");

exeDirectory = CopyMSBuild();
string exePath = Path.Combine(exeDirectory, "msbuild.exe");
string exePath = Path.Combine(exeDirectory, MSBuildExeName);
string mainRspPath = Path.Combine(exeDirectory, "msbuild.rsp");

Directory.CreateDirectory(exeDirectory);
Expand Down Expand Up @@ -1070,7 +1076,7 @@ public void ProjectDirectoryIsMSBuildExeDirectory()
directory = CopyMSBuild();
string projectPath = Path.Combine(directory, "my.proj");
string rspPath = Path.Combine(directory, "msbuild.rsp");
string exePath = Path.Combine(directory, "msbuild.exe");
string exePath = Path.Combine(directory, MSBuildExeName);

string content = ObjectModelHelpers.CleanupFileContents("<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'><Target Name='t'><Warning Text='[A=$(A)]'/></Target></Project>");
File.WriteAllText(projectPath, content);
Expand Down Expand Up @@ -1195,7 +1201,7 @@ public void ResponseFileInProjectDirectoryNullCase()
}
}

#region IgnoreProjectExtensionTests
#region IgnoreProjectExtensionTests

/// <summary>
/// Test the case where the extension is a valid extension but is not a project
Expand Down Expand Up @@ -1554,9 +1560,9 @@ internal string[] GetFiles(string path, string searchPattern)
return fileNamesToReturn.ToArray();
}
}
#endregion
#endregion

#region ProcessFileLoggerSwitches
#region ProcessFileLoggerSwitches
/// <summary>
/// Test the case where no file logger switches are given, should be no file loggers attached
/// </summary>
Expand Down Expand Up @@ -1800,9 +1806,9 @@ public void TestProcessFileLoggerSwitch5()
Assert.Equal(0, distributedLoggerRecords.Count); // "Expected no distributed loggers to be attached"
Assert.Equal(0, loggers.Count); // "Expected no central loggers to be attached"
}
#endregion
#endregion

#region ProcessConsoleLoggerSwitches
#region ProcessConsoleLoggerSwitches
[Fact]
public void ProcessConsoleLoggerSwitches()
{
Expand Down Expand Up @@ -1850,7 +1856,7 @@ public void ProcessConsoleLoggerSwitches()
Assert.Equal(0, string.Compare(distributedLogger.CentralLogger.Parameters, "SHOWPROJECTFILE=TRUE;Parameter1;Parameter;;;parameter;Parameter", StringComparison.OrdinalIgnoreCase)); // "Expected parameter in logger to match parameters passed in"
Assert.Equal(0, string.Compare(distributedLogger.ForwardingLoggerDescription.LoggerSwitchParameters, "SHOWPROJECTFILE=TRUE;Parameter1;Parameter;;;Parameter;Parameter", StringComparison.OrdinalIgnoreCase)); // "Expected parameter in logger to match parameter passed in"
}
#endregion
#endregion

private string CopyMSBuild()
{
Expand Down
4 changes: 2 additions & 2 deletions src/XMakeCommandLine/project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"frameworks": {
"net46": {},
"netstandard1.5": {
"netcoreapp1.0": {
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.NETCore.App": "1.0.1",
"System.Collections.NonGeneric": "4.0.1",
"System.Diagnostics.FileVersionInfo": "4.0.0",
"System.Diagnostics.Process": "4.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/dir.targets
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@

<!-- Debugging support -->
<PropertyGroup Condition="'$(NetCoreBuild)' == 'true'">
<StartAction>Program</StartAction>
<DebugEngines>{2E36F1D4-B23C-435D-AB41-18E608940038}</DebugEngines>
<TestHost Condition="'$(OsEnvironment)' == 'Windows_NT'">dotnet.exe</TestHost>
<TestHost Condition="'$(OsEnvironment)' != 'Windows_NT'">dotnet</TestHost>
<StartProgram Condition="'$(StartProgram)'==''">$(DeploymentDir)\$(TestHost)</StartProgram>
<StartArguments>msbuild.exe</StartArguments>
<StartArguments>$(TargetPath)</StartArguments>
</PropertyGroup>


Expand All @@ -92,7 +93,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(NetCoreBuild)' == 'true'">
<NuGetTargetMoniker>.NETStandard,Version=$(TargetFrameworkVersion)</NuGetTargetMoniker>
<NuGetTargetMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</NuGetTargetMoniker>
</PropertyGroup>

<Import Project="$(RepoRoot)\targets\GenApi.targets" Condition="'$(OS)' == 'Windows_NT'" />
Expand Down
2 changes: 1 addition & 1 deletion src/nuget/MSBuild.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
</metadata>
<files>
<file src="_._" target="lib\netstandard1.3" />
<file src="MSBuild.exe" target="runtimes\any\native" />
<file src="MSBuild.dll" target="runtimes\any\native\MSBuild.exe" />
</files>
</package>

0 comments on commit c4cdc08

Please sign in to comment.