Skip to content

Commit

Permalink
Fix publish targets
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed Nov 6, 2023
1 parent 95fba96 commit 870e908
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
6 changes: 6 additions & 0 deletions examples/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<!-- False is the default, but this overrides the True value in the project root. -->
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion examples/aot-module/aot-module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishAot>true</PublishAot>
<PublishNodeModule>true</PublishNodeModule>
Expand Down
14 changes: 11 additions & 3 deletions examples/aot-npm-package/lib/aot-npm-package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>

<!-- The C# xmldoc file is converted to comments in the generated TS type definitions. -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- `dotnet publish` will produce node module files in $(PublishDir), with
.node native AOT binary files under $(RuntimeIdentifier) subdirectories. -->
<PublishAot>true</PublishAot>
<PublishNodeModule>true</PublishNodeModule>
<PublishDir>bin</PublishDir><!-- Publish the .node binary to this location. -->
<PublishDir>bin</PublishDir>
<PublishMultiPlatformNodeModule>true</PublishMultiPlatformNodeModule>

<!-- `dotnet publish` will produce an npm package in the $(PackageOutputPath) directory. -->
<!-- `package.json` is required in the project directory; `.npmignore` is also recommended. -->
<PackNpmPackage>true</PackNpmPackage>
<PackageOutputPath>pkg</PackageOutputPath><!-- Publish the npm .tgz packge to this location.-->
<PackageOutputPath>pkg</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion examples/dotnet-module/dotnet-module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<OutDir>bin</OutDir>
<LangVersion>10</LangVersion>
Expand Down
1 change: 0 additions & 1 deletion examples/hermes-engine/hermes-engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Hermes.Example</RootNamespace>
Expand Down
1 change: 0 additions & 1 deletion examples/semantic-kernel/semantic-kernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<RestorePackagesPath>$(MSBuildThisFileDirectory)/pkg</RestorePackagesPath>
<OutDir>bin</OutDir>
<NodeApiAssemblyJSModuleType>esm</NodeApiAssemblyJSModuleType>
Expand Down
1 change: 0 additions & 1 deletion examples/winui-fluid/winui-fluid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<TargetPlatformMinVersion>10.0.22000.0</TargetPlatformMinVersion>
<OutputType>WinExe</OutputType>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>

<!-- WinUI 3 -->
<UseWinUI>true</UseWinUI>
Expand Down
1 change: 0 additions & 1 deletion examples/wpf/WpfExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<RestorePackagesPath>$(MSBuildThisFileDirectory)/pkg</RestorePackagesPath>
<OutDir>bin</OutDir>
<NodeApiAssemblyJSModuleType>esm</NodeApiAssemblyJSModuleType>
Expand Down
23 changes: 14 additions & 9 deletions src/NodeApi/NodeApi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
BeforeTargets="PublishManagedAssembly"
Condition=" '$(PublishNodeModule)' == 'true' "
>
<!-- Rename the native library (and its symbols file) to have a .node extension. -->
<!-- Put them in a rid-specific subdirectory to support publishing for multiple platforms. -->

<MakeDir Directories="$(PublishDir)$(RuntimeIdentifier)" />
<!-- If publishing a node module for for multiple platforms, use an rid-specific subdir. -->
<PropertyGroup>
<PublishNodeModuleDir Condition=" '$(PublishMultiPlatformNodeModule)' != 'true' ">$(PublishDir)</PublishNodeModuleDir>
<PublishNodeModuleDir Condition=" '$(PublishMultiPlatformNodeModule)' == 'true' ">$(PublishDir)$(RuntimeIdentifier)/</PublishNodeModuleDir>
</PropertyGroup>
<MakeDir Directories="$(PublishNodeModuleDir)" />

<!-- Rename/move the native library (and its symbols file) to have a .node extension. -->
<Move SourceFiles="$(PublishDir)$(TargetName)$(NativeBinaryExt)"
DestinationFiles="$(PublishDir)$(RuntimeIdentifier)/$(TargetName).node" />
DestinationFiles="$(PublishNodeModuleDir)$(TargetName).node" />
<Move Condition="Exists('$(PublishDir)$(TargetName).pdb')"
SourceFiles="$(PublishDir)$(TargetName).pdb"
DestinationFiles="$(PublishDir)$(RuntimeIdentifier)/$(TargetName).node.pdb" />
DestinationFiles="$(PublishNodeModuleDir)$(TargetName).node.pdb" />
<Move Condition="Exists('$(PublishDir)$(TargetName).so.dbg')"
SourceFiles="$(PublishDir)$(TargetName).so.dbg"
DestinationFiles="$(PublishDir)$(RuntimeIdentifier)/$(TargetName).node.dbg" />
DestinationFiles="$(PublishNodeModuleDir)$(TargetName).node.dbg" />

<!-- Add a non-rid-specific JS file that redirects to the rid-specific binary. -->
<!-- (The rid code is copied from node-api-dotnet/init.js.) -->
<WriteLinesToFile File="$(PublishDir)$(TargetName).js" Overwrite="true" Lines=";
<!-- (The rid code is the same as node-api-dotnet/init.js.) -->
<WriteLinesToFile Condition=" '$(PublishMultiPlatformNodeModule)' == 'true' "
File="$(PublishDir)$(TargetName).js" Overwrite="true" Lines=";
const ridPlatform =
process.platform === 'win32' ? 'win' :
process.platform === 'darwin' ? 'osx' :
Expand All @@ -36,6 +40,7 @@ module.exports = require(`./${rid}/$(TargetName).node`);
BeforeTargets="PublishManagedAssembly"
Condition=" '$(PackNpmPackage)' == 'true' "
>
<MakeDir Directories="$(PackageOutputPath)" />
<Exec Command="npm pack --pack-destination=&quot;$(PackageOutputPath)&quot;" />
</Target>
</Project>

0 comments on commit 870e908

Please sign in to comment.