Skip to content

Local Nuget package building

Dilorfin edited this page Sep 3, 2022 · 12 revisions

Requirements

  • CMake >=3.8
  • C compiler (supported: CLang, MSVC, GCC; however mainstream is CLang)
  • dotnet (Supporting .Net Standard 1.1)

Nuget Creation

Build binaries

For now this commands should be executed with admin privileges, e.g. from the root project directory

cmake . -Bcmake-build-release -DCMAKE_BUILD_TYPE=Release
cmake --build cmake-build-release --config=Release

Place binaries

In the src/CpuFeaturesDotNet directory should be created next structure:

runtimes/%{{rid}}/native/ (i.e. src/CpuFeaturesDotNet/runtimes/${{rid}}/native/)

Each binary file should be placed respectively to it's Runtime Identifier (rid can be found at Microsoft documentation).

For example at the moment cpu_features.NET pipeline creates such files:

  • src/CpuFeaturesDotNet/runtimes/osx-x64/native/cpu_features_dotnet.x64.dylib
  • src/CpuFeaturesDotNet/runtimes/win-x64/native/cpu_features_dotnet.x64.dll
  • src/CpuFeaturesDotNet/runtimes/linux-x64/native/cpu_features_dotnet.x64.so

Configure C# project

In src/CpuFeaturesDotNet/CpuFeaturesDotNet.csproj should be placed configuration for each binary that is used.

⚠️ Be careful: cmake generating overrides csproj for local development with config for only current host OS & arch

<ItemGroup>
  <Content Include="runtimes\win-x64\native\cpu_features_dotnet.x64.dll">
    <PackagePath>runtimes\win-x64\native\cpu_features_dotnet.x64.dll</PackagePath>
    <Pack>true</Pack>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

Dotnet

Just few commands in root project directory

dotnet build "src/CpuFeaturesDotNet/CpuFeaturesDotNet.csproj" -c Release
dotnet pack -c Release -o out

Get nuget package

Your nuget package should be located in out folder (or whatever folder you set in previous step).