SyZero.AspNetCore.SpaProxy 1.1.9

dotnet add package SyZero.AspNetCore.SpaProxy --version 1.1.9
                    
NuGet\Install-Package SyZero.AspNetCore.SpaProxy -Version 1.1.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyZero.AspNetCore.SpaProxy" Version="1.1.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.AspNetCore.SpaProxy" Version="1.1.9" />
                    
Directory.Packages.props
<PackageReference Include="SyZero.AspNetCore.SpaProxy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SyZero.AspNetCore.SpaProxy --version 1.1.9
                    
#r "nuget: SyZero.AspNetCore.SpaProxy, 1.1.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SyZero.AspNetCore.SpaProxy@1.1.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SyZero.AspNetCore.SpaProxy&version=1.1.9
                    
Install as a Cake Addin
#tool nuget:?package=SyZero.AspNetCore.SpaProxy&version=1.1.9
                    
Install as a Cake Tool

SyZero.AspNetCore.SpaProxy

SyZero 的 SPA 开发代理和前端构建扩展。

功能

  • 生成 spa.proxy.json
  • 提供 HostingStartup 开发代理
  • 构建时自动执行前端工程
  • 发布时自动复制前端 distwwwroot

安装

dotnet add package SyZero.AspNetCore.SpaProxy

常用配置

<PropertyGroup>
  <SpaRoot>..\Foo.Frontend\</SpaRoot>
  <SpaProxyLaunchCommand>npm run dev</SpaProxyLaunchCommand>
  <SpaProxyServerUrl>http://localhost:5173</SpaProxyServerUrl>
  <BuildFrontendOnBuild>true</BuildFrontendOnBuild>
  <FrontendProjectPath>..\Foo.Frontend\Foo.Frontend.esproj</FrontendProjectPath>
  <FrontendDistDir>..\Foo.Frontend\dist</FrontendDistDir>
</PropertyGroup>

开发期启动

项目启动后,SyZero.AspNetCore.SpaProxy 会:

  • 读取输出目录中的 spa.proxy.json
  • 检查 SpaProxyServerUrl 是否已可访问
  • 如果前端 dev server 未启动,则执行 SpaProxyLaunchCommand
  • 当浏览器访问 HTML 路由时,重定向到前端 dev server

dotnet run

如果走 launchSettings.json profile,仍建议保留:

{
  "environmentVariables": {
    "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SyZero.AspNetCore.SpaProxy"
  }
}

dotnet watch run

SyZero.AspNetCore.SpaProxy 1.1.8 开始,包会在 ComputeRunArguments 阶段自动给 dotnet run / dotnet watch run 注入:

ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SyZero.AspNetCore.SpaProxy

因此下面的命令也能自动拉起前端,不依赖 launchSettings.json

dotnet watch run --no-launch-profile

注意事项

  • SpaProxyLaunchCommand 只有在 SpaProxyServerUrl 当前不可访问时才会执行;如果本机对应端口已经有前端进程在监听,代理不会重复启动。
  • 默认 SpaProxyKeepRunning=false。如果前端是由 SyZero.AspNetCore.SpaProxy 拉起的,那么后端项目停止时会一并关闭前端进程;如果希望前端常驻,可显式设置 SpaProxyKeepRunning=true
  • dotnet build 会执行前端生产构建;dotnet run / dotnet watch run 使用的是开发期代理逻辑,两者是不同链路。
  • 若更新了本地 NuGet 包版本,记得重新 restore,避免继续命中旧缓存。
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.9 100 4/19/2026
1.1.9-dev.2 52 4/19/2026
1.1.9-dev.1 62 4/17/2026
1.1.8 102 4/17/2026
1.1.6 96 4/17/2026
1.1.6-dev.1 50 4/17/2026
1.0.0 104 4/17/2026