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

Commit ab8986e

Browse files
committed
initial spike of compile, publish and run
1 parent f40dd3d commit ab8986e

19 files changed

+3407
-0
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

NuGet.Config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="AspNetCIDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
7+
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
8+
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
9+
</packageSources>
10+
</configuration>

dotnet-cli.sln

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1F391100-F011-4630-8C25-D1A5355E4F19}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5AB144A3-3D0A-4DC7-9EE8-19FDD2DF8735}"
9+
ProjectSection(SolutionItems) = preProject
10+
dotnet-compile.cmd = dotnet-compile.cmd
11+
dotnet-run.cmd = dotnet-run.cmd
12+
global.json = global.json
13+
NuGet.Config = NuGet.Config
14+
EndProjectSection
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{47858134-8A8D-4D5C-ABD5-E6630A66DA05}"
17+
EndProject
18+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestApp", "test\TestApp\TestApp.xproj", "{58808BBC-371E-47D6-A3D0-4902145EDA4E}"
19+
EndProject
20+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DotNet.Tools.DependencyResolver", "src\DotNet.Tools.DependencyResolver\DotNet.Tools.DependencyResolver.xproj", "{A5D41198-209A-461B-A191-F48B9DBECD67}"
21+
EndProject
22+
Global
23+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
24+
Debug|Any CPU = Debug|Any CPU
25+
Release|Any CPU = Release|Any CPU
26+
EndGlobalSection
27+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
28+
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{A5D41198-209A-461B-A191-F48B9DBECD67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{A5D41198-209A-461B-A191-F48B9DBECD67}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{A5D41198-209A-461B-A191-F48B9DBECD67}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{A5D41198-209A-461B-A191-F48B9DBECD67}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(NestedProjects) = preSolution
41+
{58808BBC-371E-47D6-A3D0-4902145EDA4E} = {47858134-8A8D-4D5C-ABD5-E6630A66DA05}
42+
{A5D41198-209A-461B-A191-F48B9DBECD67} = {1F391100-F011-4630-8C25-D1A5355E4F19}
43+
EndGlobalSection
44+
EndGlobal

dotnet-compile.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$OutputName = Split-Path -Leaf (Get-Location)
2+
$OutputPath = Join-Path (Get-Location) "bin"
3+
4+
if(!(Test-Path $OutputPath)) {
5+
mkdir $OutputPath | Out-Null
6+
}
7+
$OutputPath = (Convert-Path $OutputPath)
8+
9+
10+
# Resolve compilation dependencies
11+
Write-Host "Resolving dependencies..."
12+
$refs = dnx -p "$PSScriptRoot\src\DotNet.Tools.DependencyResolver" run --packages "$env:USERPROFILE\.dnx\packages" --target "DNXCore,Version=v5.0" --assets compile
13+
14+
# Resolve source files
15+
Write-Host "Finding source files..."
16+
$srcs = dnx -p "$PSScriptRoot\src\DotNet.Tools.SourceResolver" run
17+
18+
# Build csc response file
19+
$resp = @($refs | foreach { "/r:$_" })
20+
$resp += @($srcs | foreach { $_ })
21+
$resp += @(
22+
"/out:$OutputPath\$OutputName.dll"
23+
"/nostdlib"
24+
)
25+
26+
Write-Host "Compiling..."
27+
$resp > "$OutputPath\csc.rsp"
28+
csc "@$OutputPath\csc.rsp"
29+
30+
Write-Host " $OutputName -> $OutputPath\$OutputName.dll"

dotnet-publish.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$OutputName = Split-Path -Leaf (Get-Location)
2+
$OutputPath = Join-Path (Join-Path (Get-Location) "bin") "publish"
3+
4+
& $PSScriptRoot\dotnet-compile.ps1
5+
6+
if(Test-Path $OutputPath) {
7+
del -Recurse -Force $OutputPath
8+
}
9+
mkdir $OutputPath | Out-Null
10+
$OutputPath = (Convert-Path $OutputPath)
11+
12+
# Resolve runtime and native dependencies
13+
Write-Host "Resolving dependencies..."
14+
$refs = dnx -p "$PSScriptRoot\src\DotNet.Tools.DependencyResolver" run --packages "$env:USERPROFILE\.dnx\packages" --target "DNXCore,Version=v5.0/win7-x64" --assets runtime --assets native
15+
16+
# Copy everything to one directory
17+
$refs | foreach {
18+
Write-Host "Publishing $_ ..."
19+
cp $_ $OutputPath
20+
}
21+
22+
$ProjectBinary = (Join-Path (Get-Location) "bin\$OutputName.dll")
23+
Write-Host "Publishing $ProjectBinary ..."
24+
cp $ProjectBinary $OutputPath
25+
26+
# CoreConsole should have come along for the ride
27+
$CoreConsolePath = Join-Path $OutputPath "CoreConsole.exe"
28+
if(!(Test-Path $CoreConsolePath)) {
29+
throw "Unable to locate CoreConsole.exe. You must have a dependency on Microsoft.NETCore.ConsoleHost (for now ;))"
30+
}
31+
mv $CoreConsolePath (Join-Path $OutputPath "$OutputName.exe")

dotnet-run.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$OutputName = Split-Path -Leaf (Get-Location)
2+
3+
& $PSScriptRoot\dotnet-compile.ps1
4+
5+
# Still need to use DNX, but it just boots CoreCLR, no runtime involved.
6+
dnx run bin\$OutputName.exe

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"projects": [ "src", "test" ]
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>a5d41198-209a-461b-a191-f48b9dbecd67</ProjectGuid>
10+
<RootNamespace>DotNet.Tools.DependencyResolver</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
</PropertyGroup>
14+
<PropertyGroup>
15+
<SchemaVersion>2.0</SchemaVersion>
16+
</PropertyGroup>
17+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
18+
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.IO;
3+
using Microsoft.Dnx.Runtime.Common.CommandLine;
4+
5+
namespace DotNet.Tools.DependencyResolver
6+
{
7+
public class Program
8+
{
9+
public void Main(string[] args)
10+
{
11+
var app = new CommandLineApplication();
12+
app.HelpOption("-h|--help");
13+
app.Description = "Resolves the absolute path of all dependencies for a project";
14+
15+
var packages = app.Option("-p|--packages <PACKAGES_DIRECTORY>", "Path to the directories containing packages to resolve.", CommandOptionType.MultipleValue);
16+
var target = app.Option("-t|--target <TARGET_IDENTIFIER>", "The target to resolve dependencies for.", CommandOptionType.SingleValue);
17+
var output = app.Option("-o|--output <OUTPUT_FILE>", "The path in which to write the output file (formatted as text with one line per dependency)", CommandOptionType.SingleValue);
18+
var assetType = app.Option("-a|--assets <ASSET_TYPE>", "The type of assets to resolve (common values include: compile, runtime, native)", CommandOptionType.MultipleValue);
19+
var project = app.Argument("PROJECT", "The project to resolve. A directory or a path to a project.lock.json may be used. Defaults to the current directory");
20+
21+
app.OnExecute(() =>
22+
{
23+
// Check required args
24+
if(!packages.HasValue())
25+
{
26+
Console.Error.WriteLine("Missing required argument: --packages");
27+
app.ShowHelp();
28+
return 1;
29+
}
30+
if(!target.HasValue())
31+
{
32+
Console.Error.WriteLine("Missing required argument: --target");
33+
app.ShowHelp();
34+
return 1;
35+
}
36+
if(!assetType.HasValue())
37+
{
38+
Console.Error.WriteLine("Missing required argument: --assets");
39+
app.ShowHelp();
40+
return 1;
41+
}
42+
43+
var path = project.Value ?? Directory.GetCurrentDirectory();
44+
if (!path.EndsWith("project.lock.json"))
45+
{
46+
path = Path.Combine(path, "project.lock.json");
47+
}
48+
return Resolver.Execute(packages.Values, target.Value(), output.Value(), assetType.Values, path);
49+
});
50+
51+
app.Execute(args);
52+
}
53+
}
54+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Newtonsoft.Json.Linq;
6+
7+
namespace DotNet.Tools.DependencyResolver
8+
{
9+
public static class Resolver
10+
{
11+
public static int Execute(IEnumerable<string> packageDirectories, string targetName, string output, IEnumerable<string> assetTypes, string lockFilePath)
12+
{
13+
// Open the lock file
14+
var lockFile = JObject.Parse(File.ReadAllText(lockFilePath));
15+
16+
// Locate the target
17+
var target = lockFile["targets"][targetName] as JObject;
18+
if (target == null)
19+
{
20+
Console.Error.WriteLine($"Could not find target in lock file: {target}");
21+
return 1;
22+
}
23+
24+
// Iterate over each package and prepare the dependency data
25+
bool success = true;
26+
List<string> files = new List<string>();
27+
foreach (var dependency in target)
28+
{
29+
// Parse the input string
30+
var splat = dependency.Key.Split('/');
31+
var id = splat[0];
32+
var version = splat[1];
33+
34+
string packageRoot = null;
35+
foreach (var dir in packageDirectories)
36+
{
37+
var candidate = Path.Combine(dir, id, version);
38+
if (Directory.Exists(candidate))
39+
{
40+
packageRoot = candidate;
41+
break;
42+
}
43+
}
44+
45+
if (packageRoot == null)
46+
{
47+
Console.Error.WriteLine($"WARNING: Unable to locate {id} {version}");
48+
success = false;
49+
}
50+
51+
// Locate all the assets
52+
foreach (var assetType in assetTypes)
53+
{
54+
var assetList = dependency.Value[assetType] as JObject;
55+
if (assetList != null)
56+
{
57+
foreach (var asset in assetList)
58+
{
59+
var pathified = Path.Combine(asset.Key.Split('/'));
60+
if (!Path.GetFileName(pathified).Equals("_._", StringComparison.Ordinal))
61+
{
62+
var file = Path.Combine(packageRoot, pathified);
63+
if (!File.Exists(file))
64+
{
65+
Console.Error.WriteLine($"WARNING: Missing asset: {file}");
66+
success = false;
67+
}
68+
files.Add(file);
69+
Console.WriteLine(file);
70+
}
71+
}
72+
}
73+
}
74+
}
75+
76+
if (!string.IsNullOrEmpty(output))
77+
{
78+
File.WriteAllLines(output, files);
79+
}
80+
81+
return success ? 0 : 1;
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)