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

Commit

Permalink
SourceLink.Test (#147)
Browse files Browse the repository at this point in the history
* SourceLink.Test nupkg #136

* adjusted readme for trying out 2.0.0

* fix appveyor url

* remove SourceLink.props

* remove props reference mistake

* debug appveyor paths

* try removing duplicate slash

* check powershell version

* set location

* try including build output

* don't rename and separte out OutputPath

* include explicit dll reference

* forgot the $

* root cause *.targets;$(OutputPath)*.* didn't work on appveyor

* guess not, try just dlls

* explicit for msbuild projects

* adjust tool help
  • Loading branch information
ctaggart authored Feb 25, 2017
1 parent 5be8ea9 commit a99f6b1
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="sourcelink" value="https://ci.appveyor.com/nuget/sourcelink" />
<add key="sourcelink" value="https://ci.appveyor.com/nuget/sourcelink/" />
</packageSources>
</configuration>
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ SourceLink v2 is a set of dotnet and msbuild tools to help create the source lin
/sourcelink:<file> Source link info to embed into Portable PDB.
```

SourceLine v2 is [under active development](https://github.com/ctaggart/SourceLink/milestone/16) and a prerelease will be out soon. Installation will hopefully be as simple as adding a single reference to one of the SourceLink.Create NuGet packages.
A prerelease of SourceLine v2 is available. Updated docs are coming soon. Add the references below to your project file and it should run automatically on a CI server. To try it out locally, you can do `dotnet build /p:ci=true /v:n`.

``` xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFramework>netstandard1.6</TargetFramework>
<DebugType>Portable</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="2.0.0-*" />
<PackageReference Include="SourceLink.Test" Version="2.0.0-*" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.0.0-*" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.0.0-*" />
</ItemGroup>
</Project>
```
Expand Down
11 changes: 0 additions & 11 deletions SourceLink.Create.GitHub/CreateTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Build.Framework;
using MSBuildTask = Microsoft.Build.Utilities.Task;
using System.Diagnostics;
using System.Text;
using System;
using IO = System.IO;
Expand Down Expand Up @@ -33,16 +32,6 @@ public class CreateTask : MSBuildTask
[Output]
public string[] EmbeddedFiles { get; set; }

DataReceivedEventHandler LogMessageHander(MessageImportance importance)
{
return (s, e) => {
if (e.Data != null) // end
{
Log.LogMessage(importance, e.Data);
}
};
}

public override bool Execute()
{
var url = Url;
Expand Down
18 changes: 15 additions & 3 deletions SourceLink.Create.GitHub/SourceLink.Create.GitHub.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<TargetFramework>netstandard1.6</TargetFramework>
<!-- https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target -->
<IncludeBuildOutput>false</IncludeBuildOutput>

Expand All @@ -17,12 +17,24 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.0-preview-000545-01" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="14.3.0" />
</ItemGroup>

<!-- https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/extensibility -->
<ItemGroup Label="dotnet pack instructions">
<Content Include="*.targets;$(OutputPath)\*.*">
<Content Include="SourceLink.Create.GitHub.targets">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Create.GitHub.dll">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Create.GitHub.deps.json">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Create.GitHub.pdb">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
Expand Down
46 changes: 46 additions & 0 deletions SourceLink.Test/SourceLink.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<!-- https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target -->
<IncludeBuildOutput>false</IncludeBuildOutput>

<Authors>Cameron Taggart</Authors>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<PackageIconUrl>https://ctaggart.github.io/SourceLink/SourceLink128.jpg</PackageIconUrl>
<PackageProjectUrl>https://github.com/ctaggart/SourceLink</PackageProjectUrl>
<PackageTags>sourcelink pdb symbols git sourceindexing debugging sourceserver build</PackageTags>
<Description>
SourceLink: Source Code On Demand
Source Link your Portable PDB files to allow source code to be downloaded on demand
</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="14.3.0" />
</ItemGroup>

<!-- https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/extensibility -->
<ItemGroup Label="dotnet pack instructions">
<Content Include="SourceLink.Test.targets">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Test.dll">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Test.deps.json">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Test.pdb">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="..\SourceLink.Create.GitHub\Process.cs" Link="Process.cs" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions SourceLink.Test/SourceLink.Test.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask TaskName="SourceLink.Test.TestTask" AssemblyFile="SourceLink.Test.dll" />

<PropertyGroup>
<!-- enable only in CI environments by default -->
<SourceLinkTest Condition="'$(SourceLinkTest)' == ''">$(CI)</SourceLinkTest>
<CompileDependsOn Condition="'$(SourceLinkTest)' == 'true'">$(CompileDependsOn);SourceLinkTest</CompileDependsOn>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == ''">$(PdbFile)</SourceLinkPdb>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == ''">$(IntermediateOutputPath)$(TargetName).pdb</SourceLinkPdb>
</PropertyGroup>

<Target Name="SourceLinkTest">
<SourceLink.Test.TestTask Pdb="$(SourceLinkPdb)" />
</Target>
</Project>
39 changes: 39 additions & 0 deletions SourceLink.Test/TestTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Build.Framework;
using MSBuildTask = Microsoft.Build.Utilities.Task;
using System.Diagnostics;
using System.Text;

namespace SourceLink.Test
{
public class TestTask : MSBuildTask
{
[Required]
public string Pdb { get; set; }

public override bool Execute()
{
var sbArgs = new StringBuilder();
sbArgs.Append("sourcelink test");
sbArgs.Append(" \"" + Pdb + "\"");
var args = sbArgs.ToString();

var create = Process.RunAndGetOutput("dotnet", args);
if (create.ExitCode != 0)
{
Log.LogMessage(MessageImportance.High, "dotnet " + args);
foreach (var line in create.OutputLines)
Log.LogMessage(MessageImportance.High, line);
Log.LogError("exit code " + create.ExitCode + " when running: dotnet " + args);
}
else
{
Log.LogMessage(MessageImportance.Normal, "dotnet " + args);
foreach (var line in create.OutputLines)
Log.LogMessage(MessageImportance.Normal, line);
}

return !Log.HasLoggedErrors;
}

}
}
14 changes: 14 additions & 0 deletions SourceLink.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-sourcelink-git", "do
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{13B28F5D-43CA-4243-A932-3352BB788216}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceLink.Test", "SourceLink.Test\SourceLink.Test.csproj", "{76A52AA7-0433-4B6C-831C-2C2CEB371082}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,6 +79,18 @@ Global
{13B28F5D-43CA-4243-A932-3352BB788216}.Release|x64.Build.0 = Release|x64
{13B28F5D-43CA-4243-A932-3352BB788216}.Release|x86.ActiveCfg = Release|x86
{13B28F5D-43CA-4243-A932-3352BB788216}.Release|x86.Build.0 = Release|x86
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|x64.ActiveCfg = Debug|x64
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|x64.Build.0 = Debug|x64
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|x86.ActiveCfg = Debug|x86
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Debug|x86.Build.0 = Debug|x86
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|Any CPU.Build.0 = Release|Any CPU
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|x64.ActiveCfg = Release|x64
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|x64.Build.0 = Release|x64
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|x86.ActiveCfg = Release|x86
{76A52AA7-0433-4B6C-831C-2C2CEB371082}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 0 additions & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.0-preview-000545-01" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170217-05" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ os: Visual Studio 2017 RC
clone_depth: 10
build_script:
- ps: |
dotnet --version
.\build.ps1
if ($lastexitcode -ne 0){ exit $lastexitcode }
test: off
Expand Down
17 changes: 10 additions & 7 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$version = '2.0.0' # the version under development, update after a release
$versionSuffix = '-a057' # manually incremented for local builds
$versionSuffix = '-a088' # manually incremented for local builds

function isVersionTag($tag){
$v = New-Object Version
Expand All @@ -17,21 +17,24 @@ if ($env:appveyor){

$pack = "pack", "-c", "release", "--include-symbols", "-o", "../bin", "/p:Version=$version$versionSuffix"

Push-Location .\dotnet-sourcelink
Set-Location $psscriptroot\dotnet-sourcelink
dotnet restore
dotnet $pack
Pop-Location

Push-Location .\dotnet-sourcelink-git
Set-Location $psscriptroot\dotnet-sourcelink-git
dotnet restore
dotnet $pack
Pop-Location

Push-Location .\SourceLink.Create.GitHub
Set-Location $psscriptroot\SourceLink.Create.GitHub
dotnet msbuild /t:Paths
dotnet restore
dotnet $pack
Pop-Location

Set-Location $psscriptroot\SourceLink.Test
dotnet restore
dotnet $pack

Set-Location $psscriptroot
bash .\build-rename.sh

# testing on local nuget feed
Expand Down
18 changes: 11 additions & 7 deletions dotnet-sourcelink-git/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication()
{
Name = "dotnet sourcelink-git",
};
var app = new CommandLineApplication();
app.FullName = "Source Code On Demand";
app.HelpOption("-h|--help");

app.Command("repo", PrintRepo);
Expand All @@ -25,6 +23,7 @@ public static int Main(string[] args)

if (args.Length == 0)
{
Console.WriteLine("SourceLink Git " + Version.GetAssemblyInformationalVersion());
app.ShowHelp();
return 0;
}
Expand Down Expand Up @@ -258,12 +257,12 @@ public static void Create(CommandLineApplication command)
js.Serialize(sw, json);
}

//var embedFile = embedOption.Value();
//if (String.IsNullOrEmpty(embedFile))
var embedFile = Path.ChangeExtension(file, ".embed");
if (embedFiles.Count > 0)
{
Console.WriteLine("embedding " + embedFiles.Count + " source files");
//var embedFile = embedOption.Value();
//if (String.IsNullOrEmpty(embedFile))
var embedFile = Path.ChangeExtension(file, ".embed");
using (var sw = new StreamWriter(File.OpenWrite(embedFile)))
{
foreach (var sf in embedFiles)
Expand All @@ -272,6 +271,11 @@ public static void Create(CommandLineApplication command)
}
}
}
else
{
if (File.Exists(embedFile))
File.Delete(embedFile);
}

return errors == 0 ? 0 : 1;
});
Expand Down
1 change: 1 addition & 0 deletions dotnet-sourcelink-git/dotnet-sourcelink-git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<Compile Include="..\dotnet-sourcelink\SourceLinkJson.cs" Link="SourceLinkJson.cs" />
<Compile Include="..\dotnet-sourcelink\System.cs" Link="System.cs" />
<Compile Include="..\dotnet-sourcelink\Version.cs" Link="Version.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp.Portable" Version="0.24.10" />
Expand Down
10 changes: 4 additions & 6 deletions dotnet-sourcelink/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication()
{
Name = "dotnet sourcelink",
FullName = "SourceLink: Source Code On Demand",
Description = "Source Link your Portable PDB files to allow source code to be downloaded on demand from the source code repository host"
};
var app = new CommandLineApplication();
app.FullName = "Source Code On Demand";
app.HelpOption("-h|--help");

app.Command("print-json", PrintJson);
Expand All @@ -31,6 +27,7 @@ public static int Main(string[] args)

if (args.Length == 0)
{
Console.WriteLine("SourceLink " + Version.GetAssemblyInformationalVersion());
app.ShowHelp();
return 0;
}
Expand Down Expand Up @@ -301,6 +298,7 @@ public static IEnumerable<Document> GetDocumentsWithUrls(string pdb)

public static string GetUrl(string file, SourceLinkJson json)
{
if (json == null) return null;
foreach (var key in json.documents.Keys)
{
if (key.Contains("*"))
Expand Down
15 changes: 15 additions & 0 deletions dotnet-sourcelink/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;

namespace SourceLink
{
public static class Version
{
public static string GetAssemblyInformationalVersion()
{
var assembly = Assembly.GetEntryAssembly();
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (attribute == null) return null;
return attribute.InformationalVersion;
}
}
}

0 comments on commit a99f6b1

Please sign in to comment.