This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dotnet-build3 Adding msbuild execution command to cli
- Loading branch information
Showing
17 changed files
with
493 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.