Skip to content

Commit

Permalink
fix: static files in aot and dotnet tool versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne4to committed Jan 28, 2024
1 parent 12374f1 commit ea12662
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 50 deletions.
10 changes: 10 additions & 0 deletions scripts/clean-artifacts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$RepositoryRoot = Split-Path $PSScriptRoot
$ArtifactsRoot = Join-Path $RepositoryRoot 'artifacts'

Remove-Item $ArtifactsRoot -Force -Recurse -ErrorAction SilentlyContinue
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter bin | Remove-Item -Recurse
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter obj | Remove-Item -Recurse
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter app | Remove-Item -Recurse
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter nupkg | Remove-Item -Recurse
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter build | Remove-Item -Recurse
Get-ChildItem $RepositoryRoot -Directory -Recurse -Filter node_modules | Remove-Item -Recurse
15 changes: 11 additions & 4 deletions scripts/publish-native-aot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ function Assert-ExitCode {

$Configuration = 'ReleaseAOT'
$RepositoryRoot = Split-Path $PSScriptRoot
$SpaRoot = Join-Path $RepositoryRoot 'src/Heartbeat/ClientApp'
$PublishProject = Join-Path $RepositoryRoot 'src/Heartbeat/Heartbeat.csproj'
$ArtifactsRoot = Join-Path $RepositoryRoot 'artifacts'

Push-Location
try {
$SpaRoot
Set-Location $SpaRoot
npm install
npm run build

Set-Location $RepositoryRoot

# [xml]$XmlConfig = Get-Content 'Directory.Build.props'
Expand All @@ -37,7 +44,7 @@ try {
# $VersionSuffix = "rc.$(Get-Date -Format 'yyyy-MM-dd-HHmm')"
# $PackageVersion = "$VersionPrefix-$VersionSuffix"

dotnet clean --configuration $Configuration
# dotnet clean --configuration $Configuration

# https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
# $Runtimes = @('win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
Expand All @@ -46,12 +53,12 @@ try {
# $env:PROCESSOR_ARCHITECTURE
foreach ($Runtime in $Runtimes) {
$OutDir = Join-Path $ArtifactsRoot $Runtime
Write-Host "Publish AOT version for $Runtime to $OutDir"
dotnet publish --configuration $Configuration --runtime $Runtime --output $OutDir
Write-Host "Publish native AOT version for $Runtime to $OutDir"
dotnet publish --configuration $Configuration --runtime $Runtime --output $OutDir $PublishProject
Assert-ExitCode

Write-Host "Files in $OutDir"
Get-ChildItem $OutDir
Get-ChildItem $OutDir | Select-Object -Property Length,Name
}

# TODO zip?
Expand Down
11 changes: 9 additions & 2 deletions scripts/reinstall-dev-tool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ function Assert-ExitCode {
}

$RepositoryRoot = Split-Path $PSScriptRoot
$SpaRoot = Join-Path $RepositoryRoot 'src/Heartbeat/ClientApp'
$PublishProject = Join-Path $RepositoryRoot 'src/Heartbeat/Heartbeat.csproj'

Push-Location
try
{
$SpaRoot
Set-Location $SpaRoot
npm install
npm run build

Set-Location $RepositoryRoot

[xml]$XmlConfig = Get-Content 'Directory.Build.props'
Expand All @@ -23,9 +30,9 @@ try
dotnet tool uninstall -g Heartbeat
dotnet clean --configuration Release
$VersionSuffix = "rc.$(Get-Date -Format 'yyyy-MM-dd-HHmm')"
dotnet publish
dotnet publish $PublishProject
Assert-ExitCode
dotnet pack --version-suffix $VersionSuffix
dotnet pack --version-suffix $VersionSuffix $PublishProject
Assert-ExitCode
$PackageVersion = "$VersionPrefix-$VersionSuffix"
dotnet tool install --global --add-source ./src/Heartbeat/nupkg Heartbeat --version $PackageVersion
Expand Down
70 changes: 29 additions & 41 deletions src/Heartbeat/Heartbeat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'ReleaseAOT'">
<EmbeddedResource Include="$(SpaRoot)build\**"/>
</ItemGroup>

<PropertyGroup>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
Expand All @@ -42,74 +38,66 @@
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
<None Include="../../README.md" Pack="true" PackagePath="\" />
<None Remove="temp.props" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Heartbeat.Runtime\Heartbeat.Runtime.csproj"/>
<ProjectReference Include="..\Heartbeat.Runtime\Heartbeat.Runtime.csproj" />
</ItemGroup>

<!-- <ItemGroup>-->
<!-- <Reference Include="Microsoft.Diagnostics.Runtime">-->
<!-- <HintPath>..\..\..\clrmd\artifacts\bin\Microsoft.Diagnostics.Runtime\Debug\net6.0\Microsoft.Diagnostics.Runtime.dll</HintPath>-->
<!--
<HintPath>..\..\..\clrmd\artifacts\bin\Microsoft.Diagnostics.Runtime\Debug\net6.0\Microsoft.Diagnostics.Runtime.dll</HintPath>-->
<!-- </Reference>-->
<!-- </ItemGroup>-->

<ItemGroup Condition="'$(Configuration)' == 'DebugOpenAPI'">
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.1"/>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.1"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/>
<!-- Don't publish the SPA source files, but do show them in the project files list -->
<Content Remove="$(SpaRoot)**" />
<None Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>

<ItemGroup>
<!-- Don't publish the SPA source files, but do show them in the project files list -->
<Content Remove="$(SpaRoot)**"/>
<None Remove="$(SpaRoot)**"/>
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**"/>
<ItemGroup Condition="'$(Configuration)' == 'ReleaseAOT'">
<EmbeddedResource Include="$(SpaRoot)build\**" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\"/>
<Folder Include="wwwroot\" />
</ItemGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE."/>
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..."/>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install"/>
</Target>

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition="'$(Configuration)' == 'Release'">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install"/>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build"/>
<!-- <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" /> -->

<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)build\**"/>
<DistFiles Include="$(SpaRoot)build\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
<CopyToPublishDirectory Condition="'$(Configuration)' == 'ReleaseAOT'">Never</CopyToPublishDirectory>
<CopyToPublishDirectory Condition="'$(Configuration)' != 'ReleaseAOT'">PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>false</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>

</Project>
</Project>
19 changes: 16 additions & 3 deletions src/Heartbeat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@
using StringDuplicate = Heartbeat.Host.Controllers.StringDuplicate;
using StringInfo = Heartbeat.Host.Controllers.StringInfo;

PrintFlatFiles();
PrintFiles();

#if OPENAPI
Console.WriteLine("Generating OpenAPI contract");
var builder = WebApplication.CreateSlimBuilder(args);

// workaround for https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2550
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});

// workaround for https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2550
builder.Services.ConfigureHttpJsonOptions(options =>
{
// options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
// options.SerializerOptions.Converters.Add(new JsonStringEnumConverter<GCSegmentKind>());
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});

Expand All @@ -67,6 +66,7 @@ static void MainWeb(WebCommandOptions options, string[] args)
#if !DEBUG && !AOT
// fix for static files when running as dotnet tool
string rootDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!;
Console.WriteLine($"Set current directory = {rootDir}");
Directory.SetCurrentDirectory(rootDir);
#endif

Expand Down Expand Up @@ -211,6 +211,19 @@ static void PrintFiles()
}
}

[Conditional("AOT")]
static void PrintFlatFiles()
{
Console.WriteLine("Embedded files:");
IFileProvider fileProvider = new EmbeddedFileProvider(typeof(Program).Assembly);
var contents = fileProvider.GetDirectoryContents("/");
using IEnumerator<IFileInfo> enumerator = contents.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Current.Name);
}
}

static class DumpHandler
{
public static DumpInfo GetInfo([FromServices] RuntimeContext context)
Expand Down
75 changes: 75 additions & 0 deletions src/Heartbeat/temp.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

<!-- Ensure Node.js is installed -->
<!--
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<Exec Command="node -version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
-->

<!-- <Target Name="CustomActionsBeforePublish" BeforeTargets="BeforePublish">
<Message Text="DEBUGAOT Inside BeforePublish" Importance="high" />
</Target>
<Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish">
<Message Text="DEBUGAOT Inside AfterPublish" Importance="high" />
</Target> -->

<!-- <Target Name="CustomActionsBeforePublish222" BeforeTargets="BeforePublish" Condition="'$(Configuration)' == 'ReleaseAOT'">
<Message Text="DEBUGAOT Inside BeforePublish ReleaseAOTReleaseAOTReleaseAOTReleaseAOT" Importance="high" />
</Target> -->

<!-- https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions?view=vs-2022#supported-elements -->
<!--
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<Message Text="DEBUGAOT Publish frontend in release mode" Importance="high" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install"/>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build"/>
<ItemGroup>
<DistFiles Include="$(SpaRoot)build\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<ExcludeFromSingleFile>false</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
-->

<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<!-- Include the newly-built files in the publish output -->
<!-- Condition="'$(Configuration)' == 'ReleaseAOT'" -->

<!-- <ItemGroup Condition="'$(Configuration)' != 'ReleaseAOT'">
<DistFiles Include="$(SpaRoot)build\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup> -->




<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition="'$(Configuration)' == 'Debug'">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)build\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>

0 comments on commit ea12662

Please sign in to comment.