Enable single file exe for QuicTrace (#2204)

* Enable single file exe for QuicTrace

* Extra newline
This commit is contained in:
Thad House 2021-12-07 13:19:40 -08:00 коммит произвёл GitHub
Родитель abb91f74e5
Коммит eec1bdaa05
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 57 добавлений и 20 удалений

Просмотреть файл

@ -32,27 +32,20 @@ foreach ($RID in $RIDs) {
$FullOutputFile = Join-Path $BinFolder "Release/net6.0/$RID/publish/$ExeName"
# Publish Non Trimmed Non Single File
dotnet publish $ToolDir -r $RID -c Release --self-contained true
# Publish Non Trimmed
dotnet publish $ToolDir -r $RID -c Release -p:PublishSingleFile=true --self-contained true -p:EnableCompressionInSingleFile=true
$ArtifactFolder = Join-Path $RootOutputFolder $RID
if (!(Test-Path $ArtifactFolder)) { New-Item -Path $ArtifactFolder -ItemType Directory -Force | Out-Null }
Copy-Item $FullOutputFile $ArtifactFolder
# # Publish Non Trimmed
# dotnet publish $ToolDir -r $RID -c Release -p:PublishSingleFile=true --self-contained true -p:EnableCompressionInSingleFile=true
# Clear out bin folder
if (Test-Path $BinFolder) { Remove-Item $BinFolder -Recurse -Force | Out-Null }
# $ArtifactFolder = Join-Path $RootOutputFolder $RID
# if (!(Test-Path $ArtifactFolder)) { New-Item -Path $ArtifactFolder -ItemType Directory -Force | Out-Null }
# Copy-Item $FullOutputFile $ArtifactFolder
# Publish Trimmed
dotnet publish $ToolDir -r $RID -c Release -p:PublishSingleFile=true --self-contained true -p:EnableCompressionInSingleFile=true -p:PublishTrimmed=true
# # Clear out bin folder
# if (Test-Path $BinFolder) { Remove-Item $BinFolder -Recurse -Force | Out-Null }
# # Publish Trimmed
# dotnet publish $ToolDir -r $RID -c Release -p:PublishSingleFile=true --self-contained true -p:EnableCompressionInSingleFile=true -p:PublishTrimmed=true
# $TrimmedArtifactFolder = Join-Path $ArtifactFolder "trimmed"
# if (!(Test-Path $TrimmedArtifactFolder)) { New-Item -Path $TrimmedArtifactFolder -ItemType Directory -Force | Out-Null }
# Copy-Item $FullOutputFile $TrimmedArtifactFolder
$TrimmedArtifactFolder = Join-Path $ArtifactFolder "trimmed"
if (!(Test-Path $TrimmedArtifactFolder)) { New-Item -Path $TrimmedArtifactFolder -ItemType Directory -Force | Out-Null }
Copy-Item $FullOutputFile $TrimmedArtifactFolder
}

Просмотреть файл

@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.74" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent.SupportFiles" Version="1.0.23" />
<PackageReference Include="Microsoft.Performance.SDK" Version="1.0.9-rc1" />
<PackageReference Include="Microsoft.Performance.SDK" Version="1.0.14-rc1" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)..\..\LICENSE">

Просмотреть файл

@ -61,7 +61,20 @@ namespace QuicTrace
//
// Create our runtime environment, add file, enable cookers, and process.
//
using var dataSources = DataSourceSet.Create();
PluginSet pluginSet;
if (string.IsNullOrWhiteSpace(typeof(QuicEtwSource).Assembly.Location))
{
// Single File EXE
pluginSet = PluginSet.Load(new[] { Environment.CurrentDirectory }, new SingleFileAssemblyLoader());
}
else
{
pluginSet = PluginSet.Load();
}
using var dataSources = DataSourceSet.Create(pluginSet);
dataSources.AddFile(filePath);
var info = new EngineCreateInfo(dataSources.AsReadOnly());
using var runtime = Engine.Create(info);

Просмотреть файл

@ -5,8 +5,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Performance.SDK" Version="1.0.9-rc1" />
<PackageReference Include="Microsoft.Performance.Toolkit.Engine" Version="1.0.9-rc1" />
<PackageReference Include="Microsoft.Performance.SDK" Version="1.0.14-rc1" />
<PackageReference Include="Microsoft.Performance.Toolkit.Engine" Version="1.0.14-rc1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\dll\QuicTraceLib.csproj" />

Просмотреть файл

@ -0,0 +1,31 @@
using System;
using System.Reflection;
using Microsoft.Performance.SDK;
using Microsoft.Performance.SDK.Runtime;
namespace QuicTrace
{
internal class SingleFileAssemblyLoader : IAssemblyLoader
{
private readonly string CurrentExePath = Environment.ProcessPath!;
public bool SupportsIsolation => false;
public bool IsAssembly(string path)
{
return path == CurrentExePath;
}
public Assembly? LoadAssembly(string assemblyPath, out ErrorInfo error)
{
if (assemblyPath != CurrentExePath)
{
error = new ErrorInfo(ErrorCodes.AssemblyLoadFailed, $"AssemblyPath must be {CurrentExePath}, was {assemblyPath}");
return null;
}
error = ErrorInfo.None;
return typeof(QuicEtwSource).Assembly;
}
}
}