Skip to content

MSBuild Properties

The following properties can be used to customize the build processes for generating and packaging .NET projects for use from JavaScript.

Property NameDescription
GenerateNodeApiTypeDefinitionsSet to true to generate TypeScript type definitions for .NET APIs in the current project. (This is enabled by default when referencing the Microsoft.JavaScript.NodeApi.Generator package.) See Develop a Node.js addon module.
GenerateNodeApiTypeDefinitionsForReferencesSet to true to generate TypeScript type definitions for .NET APIs in assemblies referenced by the current project. (This is enabled by default when an empty project references the Microsoft.JavaScript.NodeApi.Generator package.) See Dynamically invoke .NET APIs from JavaScript.
NodeApiTypeDefinitionsFileNameName of the type-definitions file generated for a project. Defaults to $(TargetName).d.ts.
NodeApiTypeDefinitionsEnableWarningsSet to true to enable warnings when generating type definitions. The warnings are suppressed by default because they can be verbose when referencing system or external assemblies.
NodeApiJSModuleTypeSet to either commonjs or esm to specify the module system used by the generated type definitions. If unspecified, the module type is detected automatically from package.json, which is usually correct.
NodeApiTargetFrameworkTarget framework moniker that will be loaded at runtime for the Node API .NET host. Default is the project's $(TargetFramework).
NodeApiSystemReferenceAssemblyItem-list of assembly names (not file paths) to be included in typedefs generator. The System, System.Runtime, and System.Console assemblies are included by default. Add system assembly names to the item-list to generate type definitions for them. System assemblies are provided by the installed .NET SDK.
PublishNodeModuleSet to true to produce a Native AOT .node binary and .js module-loader script when building the Publish target. The files will be placed in the directory indicated by the PublishDir variable. See Develop a Node.js addon module with .NET Native AOT.
PublishMultiPlatformNodeModuleIf true, the published .node binary file will be placed in a sub-directory according to the targeted RuntimeIdentifier, for example win-x64. Then the publish process may be run spearately for multiple runtime-identifiers, and the module-loader script chooses the approrpriate one at runtime.
PackNpmPackageSet to true to run npm pack when building the Publish target. Requires a package.json file in the project directory. The npm package will be placed in the directory indicated by the PackageOutputPath variable. (Note this does not use the MSBuild "Pack" target because "Pack" runs before "Publish", while npm packaging must use the Native AOT binaries produced by the "Publish".)
EmitCompilerGeneratedFilesIf true (the default), the generated C# code (*.g.cs) for a node module project will be emitted under $(IntermediateOutputPath)/generated. This can be helpful for debugging the generated code for marshalling .NET APIs to/from JS.

Released under the MIT license