|
251 | 251 | </Target> |
252 | 252 |
|
253 | 253 | <!-- |
254 | | - Generate WasmExports.g.cs automatically. |
255 | | - This file contains the [UnmanagedCallersOnly] exports that must be in the main assembly. |
256 | | - Generated at build time so users don't have to write it manually. |
| 254 | + Source generator for WasmExports.g.cs. |
| 255 | + The generator scans referenced assemblies for [WasmExport] methods |
| 256 | + and generates forwarding exports with [UnmanagedCallersOnly] in the main assembly. |
| 257 | + This provides better incremental compilation support than MSBuild targets. |
257 | 258 | --> |
258 | | - <PropertyGroup> |
259 | | - <WasmExportsGeneratedDir>$(BaseIntermediateOutputPath)generated\</WasmExportsGeneratedDir> |
260 | | - <WasmExportsGeneratedFile>$(WasmExportsGeneratedDir)WasmExports.g.cs</WasmExportsGeneratedFile> |
261 | | - <WasmExportsNamespace Condition="'$(WasmExportsNamespace)' == ''">$(RootNamespace)</WasmExportsNamespace> |
262 | | - <WasmExportsNamespace Condition="'$(WasmExportsNamespace)' == ''">$(AssemblyName)</WasmExportsNamespace> |
263 | | - </PropertyGroup> |
264 | | - |
265 | | - <Target Name="GenerateWasmExports" |
266 | | - BeforeTargets="CoreCompile" |
267 | | - Inputs="$(MSBuildThisFileDirectory)WasmExports.cs.template" |
268 | | - Outputs="$(WasmExportsGeneratedFile)"> |
269 | | - <MakeDir Directories="$(WasmExportsGeneratedDir)" /> |
270 | | - |
271 | | - <PropertyGroup> |
272 | | - <_WasmExportsTemplate>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)WasmExports.cs.template'))</_WasmExportsTemplate> |
273 | | - <_WasmExportsContent>$(_WasmExportsTemplate.Replace('$NAMESPACE$', '$(WasmExportsNamespace)'))</_WasmExportsContent> |
274 | | - </PropertyGroup> |
275 | | - |
276 | | - <WriteLinesToFile File="$(WasmExportsGeneratedFile)" |
277 | | - Lines="$(_WasmExportsContent)" |
278 | | - Overwrite="true" |
279 | | - WriteOnlyWhenDifferent="true" /> |
280 | | - </Target> |
281 | | - |
282 | | - <!-- Include the generated file in compilation --> |
283 | | - <ItemGroup> |
284 | | - <Compile Include="$(WasmExportsGeneratedFile)" Visible="false" /> |
| 259 | + |
| 260 | + <!-- For local development (ZaptoWasmUseProjectReference=true), reference the generator project --> |
| 261 | + <ItemGroup Condition="'$(ZaptoWasmUseProjectReference)' == 'true'"> |
| 262 | + <ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\src\Zapto.AspNetCore.Wasm.SourceGenerator\Zapto.AspNetCore.Wasm.SourceGenerator.csproj" |
| 263 | + OutputItemType="Analyzer" |
| 264 | + ReferenceOutputAssembly="false" /> |
| 265 | + </ItemGroup> |
| 266 | + |
| 267 | + <!-- For NuGet package consumption, include the analyzer from package path --> |
| 268 | + <ItemGroup Condition="'$(ZaptoWasmUseProjectReference)' != 'true'"> |
| 269 | + <Analyzer Include="$(MSBuildThisFileDirectory)..\analyzers\dotnet\cs\Zapto.AspNetCore.Wasm.SourceGenerator.dll" /> |
285 | 270 | </ItemGroup> |
286 | 271 |
|
287 | 272 | </Project> |
0 commit comments