Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
dotnet-build3 Adding msbuild execution command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
brthor committed Jun 23, 2016
1 parent 349c409 commit 400e1db
Show file tree
Hide file tree
Showing 17 changed files with 493 additions and 24 deletions.
36 changes: 19 additions & 17 deletions Microsoft.DotNet.Cli.sln
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Configurer
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Archive", "src\Microsoft.DotNet.Archive\Microsoft.DotNet.Archive.xproj", "{35B19F22-B8C0-4849-9C35-3F809B7588B8}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-build3.Tests", "test\dotnet-build3.Tests\dotnet-build3.Tests.xproj", "{49D7318E-D198-4E2B-BBEA-3A24D805F88D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -805,22 +807,6 @@ Global
{A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|x64.ActiveCfg = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|x64.Build.0 = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|Any CPU.Build.0 = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|x64.ActiveCfg = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|x64.Build.0 = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -901,6 +887,22 @@ Global
{35B19F22-B8C0-4849-9C35-3F809B7588B8}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{35B19F22-B8C0-4849-9C35-3F809B7588B8}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{35B19F22-B8C0-4849-9C35-3F809B7588B8}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Debug|x64.ActiveCfg = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Debug|x64.Build.0 = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Release|Any CPU.Build.0 = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Release|x64.ActiveCfg = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.Release|x64.Build.0 = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -953,11 +955,11 @@ Global
{49BEB486-AB5A-4416-91EA-8CD34ABB0C9D} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{B768BD29-12BF-4C7C-B093-03193FE244D1} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{A28BD8AC-DF15-4F58-8299-98A9AE2B8726} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{1DBB7542-0345-4F4B-A84B-3B00B185D416} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{1C599FFD-FB52-4279-A8E5-465D3EC499E1} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{5DF6C9DA-6909-4EC0-909E-6913580BB4A4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{E5ED47EF-BF25-4DA9-A7FE-290C642CBF0F} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{4C3B06D5-B6D5-4E5B-A44F-3EBE52A1C759} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{35B19F22-B8C0-4849-9C35-3F809B7588B8} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{49D7318E-D198-4E2B-BBEA-3A24D805F88D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection
EndGlobal
44 changes: 44 additions & 0 deletions TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft.NuGet.props" />

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x64</PlatformTarget>
<OutputType>Exe</OutputType>
<RootNamespace>MSBuildTestApp</RootNamespace>
<AssemblyName>$(MSBuildThisFileName)</AssemblyName>
<TargetFrameworkIdentifier>NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<OutputPath>bin\$(Configuration)\netcoreapp1.0</OutputPath>
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NoStdLib>true</NoStdLib>
<NoLogo>true</NoLogo> <!-- Temp Hack: https://github.com/dotnet/roslyn/issues/12167 -->
<NuGetTargetMoniker>.NETCoreApp,Version=v1.0</NuGetTargetMoniker>
<!-- Temp Hack: Being passed through from cli, where should this come from? -->
<BaseNuGetRuntimeIdentifier Condition=" '$(BaseNuGetRuntimeIdentifier)' == '' ">win7</BaseNuGetRuntimeIdentifier>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>

<PropertyGroup>
<!-- Temp Hack: https://github.com/Microsoft/msbuild/issues/720 -->
<OverrideToolHost Condition=" '$(DotnetHostPath)' != '' and '$(OverrideToolHost)' == ''">$(DotnetHostPath)</OverrideToolHost>
</PropertyGroup>

<Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft.NuGet.targets" />

<!-- Temporary Hack, this should happen in build -->
<Target Name="AfterBuild">
<Move SourceFiles="$(TargetPath)" DestinationFiles="$(TargetDir)\$(AssemblyName).dll" />
<Copy SourceFiles="$(DotnetHostPath)" DestinationFiles="$(TargetPath)" />
</Target>
</Project>
12 changes: 12 additions & 0 deletions TestAssets/TestProjects/MSBuildTestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace MSBuildTestApp
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
28 changes: 28 additions & 0 deletions TestAssets/TestProjects/MSBuildTestApp/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0"
}
}
}
},
"runtimes": {
"win7-x64": {},
"win7-x86": {},
"win81-x64": {},
"win81-x86": {},
"win10-x64": {},
"win10-x86": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {},
"ubuntu.14.04-x64": {},
"ubuntu.16.04-x64": {},
"centos.7-x64": {},
"rhel.7.2-x64": {},
"debian.8-x64": {},
"fedora.23-x64": {},
"opensuse.13.2-x64": {}
},
}
49 changes: 49 additions & 0 deletions build.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="BuildTheWholeCli" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<!--
$(OS) is set to Unix/Windows_NT. This comes from an environment variable on Windows and MSBuild on Unix.
-->
<PlatformScriptHost Condition=" '$(OS)' == 'Windows_NT' ">powershell -NoProfile -NoLogo -Command </PlatformScriptHost>
<PlatformScriptHost Condition=" '$(OS)' != 'Windows_NT' "></PlatformScriptHost>

<PlatformScriptExtension Condition=" '$(OS)' == 'Windows_NT' ">.ps1</PlatformScriptExtension>
<PlatformScriptExtension Condition=" '$(OS)' != 'Windows_NT' ">.sh</PlatformScriptExtension>

<PlatformExeExtension Condition=" '$(OS)' == 'Windows_NT' ">.exe</PlatformExeExtension>
<PlatformExeExtension Condition=" '$(OS)' != 'Windows_NT' "></PlatformExeExtension>

<CLITargets Condition=" '$(CLITargets)' == '' ">Prepare;Compile;Test;Package;Publish</CLITargets>
</PropertyGroup>

<Target Name="BuildDotnetCliBuildFramework" Inputs="" Outputs="">
<Exec Command="$(PlatformScriptHost) $(MSBuildThisFileDirectory)/build_projects/dotnet-cli-build/build$(PlatformScriptExtension)" WorkingDirectory="$(MSBuildThisFileDirectory)"/>
<PropertyGroup>
<CliBuildFrameworkExe>$(MSBuildThisFileDirectory)/build_projects/dotnet-cli-build/bin/dotnet-cli-build$(PlatformExeExtension)</CliBuildFrameworkExe>
</PropertyGroup>
</Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework;$(CLITargets)" Name="BuildTheWholeCli"></Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Prepare">
<Exec Command="$(CliBuildFrameworkExe) Prepare" WorkingDirectory="$(MSBuildThisFileDirectory)"/>
</Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Compile">
<Exec Command="$(CliBuildFrameworkExe) Compile" WorkingDirectory="$(MSBuildThisFileDirectory)" />
</Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Test">
<Exec Command="$(CliBuildFrameworkExe) Test" WorkingDirectory="$(MSBuildThisFileDirectory)" />
</Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Package">
<Exec Command="$(CliBuildFrameworkExe) Package" WorkingDirectory="$(MSBuildThisFileDirectory)" />
</Target>

<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Publish">
<Exec Command="$(CliBuildFrameworkExe) Publish" WorkingDirectory="$(MSBuildThisFileDirectory)" />
</Target>

</Project>
27 changes: 25 additions & 2 deletions build_projects/dotnet-cli-build/CompileTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ private static void RemovePdbsFromDir(string directory)
var compilersDeps = Path.Combine(sdkOutputDirectory, "compilers.deps.json");
var compilersRuntimeConfig = Path.Combine(sdkOutputDirectory, "compilers.runtimeconfig.json");


var binaryToCorehostifyRelDir = Path.Combine("runtimes", "any", "native");
var binaryToCorehostifyOutDir = Path.Combine(sdkOutputDirectory, binaryToCorehostifyRelDir);
// Corehostify binaries
Expand All @@ -211,7 +210,7 @@ private static void RemovePdbsFromDir(string directory)
{
// Yes, it is .exe even on Linux. This is the managed exe we're working with
File.Copy(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{binaryToCorehostify}.dll"));
File.Delete(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"));
File.Move(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{binaryToCorehostify}.exe"));
var binaryToCoreHostifyDeps = Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json");

File.Copy(compilersDeps, Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json"));
Expand All @@ -221,6 +220,8 @@ private static void RemovePdbsFromDir(string directory)
{
var assetPath = Path.Combine(binaryToCorehostifyRelDir, $"{binaryToRemove}.exe").Replace(Path.DirectorySeparatorChar, '/');
RemoveAssetFromDepsPackages(binaryToCoreHostifyDeps, "runtimeTargets", assetPath);
RemoveAssetFromDepsPackages(
Path.Combine(sdkOutputDirectory, "dotnet.deps.json"), "runtimeTargets", assetPath);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -270,9 +271,31 @@ private static void RemovePdbsFromDir(string directory)
GenerateNuGetPackagesArchive(c, dotnet, sdkOutputDirectory);
}

CopyMSBuildTargetsToSDKRoot(sdkOutputDirectory);

return c.Success();
}

private static void CopyMSBuildTargetsToSDKRoot(string sdkOutputDirectory)
{
var msbuildTargetsDirectory = Path.Combine(sdkOutputDirectory, "runtimes", "any", "native");

var filesToCopy = new List<string>();
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.Targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.props", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.overridetasks", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.tasks", SearchOption.AllDirectories));

foreach (var fileFullPath in filesToCopy)
{
var fileRelativePath = fileFullPath.Substring(msbuildTargetsDirectory.Length + 1);
var destinationFilePath = Path.Combine(sdkOutputDirectory, fileRelativePath);

File.Copy(fileFullPath, destinationFilePath, true);
}
}

private static void GenerateNuGetPackagesArchive(
BuildTargetContext c,
DotNetCli dotnet,
Expand Down
1 change: 1 addition & 0 deletions build_projects/dotnet-cli-build/TestTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TestTargets
"EndToEnd",
"dotnet.Tests",
"dotnet-build.Tests",
"dotnet-build3.Tests",
"dotnet-compile.Tests",
"dotnet-compile.UnitTests",
// TODO: https://github.com/dotnet/cli/issues/3558
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class Program
["publish"] = PublishCommand.Run,
["restore"] = RestoreCommand.Run,
["run"] = RunCommand.Run,
["test"] = TestCommand.Run
["test"] = TestCommand.Run,
["build3"] = Build3Command.Run
};

public static int Main(string[] args)
Expand Down
107 changes: 107 additions & 0 deletions src/dotnet/commands/dotnet-build3/ForwardingApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Cli
{
/// <summary>
/// A class which encapsulates logic needed to forward arguments from the current process to another process
/// invoked with the dotnet.exe host.
/// </summary>
public class ForwardingApp
{
private const string s_hostExe = "dotnet";

private readonly string _forwardApplicationPath;
private readonly string[] _argsToForward;
private readonly string _depsFile;
private readonly string _runtimeConfig;
private readonly string _additionalProbingPath;
private readonly Dictionary<string, string> _environmentVariables;

private readonly string[] _allArgs;

public ForwardingApp(
string forwardApplicationPath,
string[] argsToForward,
string depsFile = null,
string runtimeConfig = null,
string additionalProbingPath = null,
Dictionary<string, string> environmentVariables = null)
{
_forwardApplicationPath = forwardApplicationPath;
_argsToForward = argsToForward;
_depsFile = depsFile;
_runtimeConfig = runtimeConfig;
_additionalProbingPath = additionalProbingPath;
_environmentVariables = environmentVariables;

var allArgs = new List<string>();
allArgs.Add("exec");

if (_depsFile != null)
{
allArgs.Add("--depsfile");
allArgs.Add(_depsFile);
}

if (_runtimeConfig != null)
{
allArgs.Add("--runtimeconfig");
allArgs.Add(_runtimeConfig);
}

if (_additionalProbingPath != null)
{
allArgs.Add("--additionalprobingpath");
allArgs.Add(_additionalProbingPath);
}

allArgs.Add(_forwardApplicationPath);
allArgs.AddRange(_argsToForward);

_allArgs = allArgs.ToArray();
}

public int Execute()
{
var processInfo = new ProcessStartInfo
{
FileName = GetHostExeName(),
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_allArgs),
UseShellExecute = false
};

if (_environmentVariables != null)
{
foreach (var entry in _environmentVariables)
{
processInfo.Environment[entry.Key] = entry.Value;
}
}

var process = new Process
{
StartInfo = processInfo
};

process.Start();
process.WaitForExit();

return process.ExitCode;
}

private string GetHostExeName()
{
return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}";
}
}
}

0 comments on commit 400e1db

Please sign in to comment.