Reconfigured project to publish as a single file.

This commit is contained in:
Harrison Deng 2022-04-24 18:31:21 -05:00
parent 1d35e8a838
commit 8abd75506c
3 changed files with 75 additions and 8 deletions

4
Jenkinsfile vendored
View File

@ -41,7 +41,9 @@ pipeline {
}
stage("Publish") {
steps {
dotnetPublish configuration: 'Release', project: 'Props', selfContained: false, unstableIfWarnings: true
// TODO: Archive things.
dotnetPublish configuration: 'Release', noRestore: true, project: 'Props', runtime: 'win-x64', sdk: 'Default .NET SDK'
dotnetPublish configuration: 'Release', noRestore: true, project: 'Props', runtime: 'linux-x64', sdk: 'Default .NET SDK'
}
}
}

View File

@ -1,7 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<!-- https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props for more information. -->
<!-- TODO: Embed wwwroot. -->
<!-- Publish arguments: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish -->
<!-- Single file docs: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview -->
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<SelfContained>true</SelfContained>
<PublishTrimmed>false</PublishTrimmed>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<UserSecretsId>aspnet-Props-20A2A991-EC61-4C06-91D2-953482026A7B</UserSecretsId>
</PropertyGroup>
@ -31,14 +40,61 @@
<ProjectReference Include="..\Props.Shop\Framework\Props.Shop.Framework.csproj" />
</ItemGroup>
<!-- Removing ASP.Net Core Identity static content -->
<!-- See https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-6.0&tabs=visual-studio#prevent-publish-of-static-identity-assets -->
<PropertyGroup>
<ResolveStaticWebAssetsInputsDependsOn>RemoveIdentityAssets</ResolveStaticWebAssetsInputsDependsOn>
</PropertyGroup>
<Target Name="RemoveIdentityAssets">
<ItemGroup>
<StaticWebAsset Remove="@(StaticWebAsset)" Condition="%(SourceId) == 'Microsoft.AspNetCore.Identity.UI'" />
</ItemGroup>
</Target>
<!-- For embedding content into single file. -->
<PropertyGroup>
<!-- See https://github.com/MicrosoftDocs/visualstudio-docs/issues/2257 -->
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
<ItemGroup>
<!-- See https://stackoverflow.com/questions/46983930/what-content-items-does-enabledefaultcontentitems-enable -->
<!-- See https://github.com/SteveSandersonMS/WebWindow/issues/41#issuecomment-590122872 -->
<!-- See https://github.com/dotnet/sdk/blob/0e0829e55c398752ddda5cc247ef3ad722a019c2/src/WebSdk/Worker/Targets/Microsoft.NET.Sdk.Worker.props -->
<!-- See https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/RazorSdk/Sdk/Sdk.Razor.StaticAssets.ProjectSystem.props -->
<!-- We disabled default content items to change some attributes, we will also add the rest here. -->
<Content Update="wwwroot\**" ExcludeFromSingleFile="false" CopyToOutputDirectory="PreserveNewest" />
<Content Include="**\*.config" ExcludeFromSingleFile="true" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" Condition="'$(ExcludeConfigFilesFromBuildOutput)'!='true'" />
<Content Include="**\*.json" ExcludeFromSingleFile="true" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" Condition="'$(ExcludeConfigFilesFromBuildOutput)'!='true'" />
<!-- When ExcludeConfigFilesFromBuildOutput is set, do not copy .,config, .json files to the build output directory. -->
<Content Include="**\*.config" ExcludeFromSingleFile="true" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" Condition="'$(ExcludeConfigFilesFromBuildOutput)'=='true'" />
<Content Include="**\*.json" ExcludeFromSingleFile="true" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" Condition="'$(ExcludeConfigFilesFromBuildOutput)'=='true'" />
<!-- Set CopyToOutputDirectory and CopyToPublishDirectory to Never for items under AppDesignerFolder ("Properties", by default) to avoid publishing launchSettings.json -->
<Content Update="$(AppDesignerFolder)\**" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" Condition="'$(AppDesignerFolder)' != ''" />
<!-- Remove Content items from other item types -->
<None Remove="wwwroot\**;**\*.json;**\*.config" />
<Compile Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
</ItemGroup>
<!-- Modules for all the shops. -->
<ItemGroup>
<None Update="shops\**\*" CopyToOutputDirectory="PreserveNewest" ExcludeFromSingleFile="true" />
</ItemGroup>
<!-- Watch configurations. -->
<ItemGroup>
<Watch Include="assets\**\*.js;assets\**\*.scss" Exclude="wwwroot\**\*;node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" !Exists('node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<!-- Ensure Node.js is installed -->
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" !Exists('node_modules') ">
<Exec Command="node --version" ContinueOnError="false">
<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." />
@ -48,7 +104,15 @@
<!-- Build static resources -->
<Target Name="BuildWebpack" BeforeTargets="Build">
<Exec Command="npm run build:dev" Condition=" '$(Configuration)' == 'Debug' " LogStandardErrorAsError="true" />
<Exec Command="npm run build:prod" Condition=" '$(Configuration)' == 'Release' " LogStandardErrorAsError="true" />
<Message Importance="high" Text="Building client-side assets..." />
<Exec Command="npm run build:dev" Condition=" '$(Configuration)' == 'Debug' " LogStandardErrorAsError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Exec Command="npm run build:prod" Condition=" '$(Configuration)' == 'Release' " LogStandardErrorAsError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="There was an issue attempting to build the static assets. To continue, fix client-side asset errors and try again." />
</Target>
</Project>

View File

@ -5,7 +5,7 @@ import shutil
PROP_SHOP_MODULES_DIR = "./Props.Shop/"
PROPS_SHOP_MODULES_DST = "./Props/shops/"
PROPS_SHOP_MODULES_DST = "./Props/shops/."
NET_VER = "net6.0"
SHOP_MODULE_GLOB = "**/bin/Release/{net_ver}/publish/*.{ext}"
@ -15,11 +15,12 @@ EXTS = ["deps.json", "dll"]
def load():
os.chdir(os.path.dirname(os.path.realpath(__file__)))
os.chdir("..")
os.makedirs(os.path.dirname(PROPS_SHOP_MODULES_DST), exist_ok=True)
for ext in EXTS:
results = glob(os.path.join(PROP_SHOP_MODULES_DIR,
SHOP_MODULE_GLOB.format(net_ver=NET_VER, ext=ext)))
for result in results:
shutil.copy(result, os.path.abspath(PROPS_SHOP_MODULES_DST))
shutil.copy(result, PROPS_SHOP_MODULES_DST)
if __name__ == "__main__":