Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Last active February 23, 2024 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbrailsford/d769c62ecacf0021d2d72ca7ebbf1732 to your computer and use it in GitHub Desktop.
Save mattbrailsford/d769c62ecacf0021d2d72ca7ebbf1732 to your computer and use it in GitHub Desktop.
  1. Add .gitignore to static assets project with wwwroot/
  2. Update vite configuration with outDir "../wwwroot/"
  3. Remove Build\Microsoft.AspNetCore.ClientAssets.targets
  4. Create Build\ClientAssets.targets with the following contents
<Project>
  
  <PropertyGroup>
    <ClientAssetsDirectory>Client\</ClientAssetsDirectory>
  </PropertyGroup>

  <Target Name="NpmInstall" Inputs="$(ClientAssetsDirectory)package.json" Outputs="$(ClientAssetsDirectory)node_modules/.install-stamp">
    <Message Text="NPM Install" Importance="High" />
    <Exec WorkingDirectory="$(ClientAssetsDirectory)" Command="npm ci --no-fund --no-audit --prefer-offline" />
    <Touch Files="$(ClientAssetsDirectory)node_modules/.install-stamp" AlwaysCreate="true" />
  </Target>

  <Target Name="NpmBuild" DependsOnTargets="NpmInstall" BeforeTargets="BeforeBuild">
    <Message Text="NPM Build" Importance="High" />
    <Exec WorkingDirectory="$(ClientAssetsDirectory)" Command="npm run build" />
  </Target>

</Project>
  1. Configure static assets proj file with
  • Set <StaticWebAssetBasePath>App_Plugins/{YOUR_PKG_ALIAS}</StaticWebAssetBasePath>
  • Remove <EnableDefaultContentItems>false</EnableDefaultContentItems>
  • Remove <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
  • Remove <Content Include="Views\**" />
  • Remove <Import Project="build\Microsoft.AspNetCore.ClientAssets.targets" />
  • Remove <Target Name="ClientAssetsBuildOutputPath" AfterTargets="ClientAssetsBuild">...</Target>
  • Add <Import Project="Build\ClientAssets.targets" /> to proj file
  1. In visual studio go to Tools -> Options -> Projects and Solutions -> ASP.NET Core
  • Set Auto build and refresh option to Auto build and refresh browser after saving
  • Set CSS hot reload to Enabled
  1. In visual studio go to Tools -> Options -> Debugging -> .NET/C++ Hot Reload
  • Check all checkbox options to true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment