Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Multiple csproj projects referenced and using NativeCallable #7215

@philcarbone

Description

@philcarbone

I can't seem to get multiple project using NativeCallableAttribute to expose these functions. Only the project that has the references (the project being compiled) has it's functions exposed as native callable functions.

Project A has a native function 'add':

[NativeCallable (EntryPoint = "add", CallingConvention = CallingConvention.StdCall)]
public static int Add (int a, int b) {
	return a + b;
}

Project B has a native function 'subtract':

[NativeCallable (EntryPoint = "subtract", CallingConvention = CallingConvention.StdCall)]
public static int Subtract (int a, int b) {
	return a - b;
}
  1. Project A has a project reference to Project B
  2. Project A is compiled
  3. I can only access Project A's 'add' function, the 'subtract' function is not available.

More Notes

Project A's nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
    <clear />
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
 </packageSources>
</configuration>

Project A's csproj file:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Library</OutputType>
    		<TargetFramework>netcoreapp3.0</TargetFramework>
    		<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
    		<NativeLib>Static</NativeLib>
    		<RootNamespace>HostA</RootNamespace>
    		<LangVersion>8.0</LangVersion>
    		<NullableContextOptions>enable</NullableContextOptions>
	</PropertyGroup>
  	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    		<LangVersion>8.0</LangVersion>
    		<NullableContextOptions>enable</NullableContextOptions>
  	</PropertyGroup>
  	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    		<LangVersion>8.0</LangVersion>
    		<NullableContextOptions>enable</NullableContextOptions>
  	</PropertyGroup>
	<ItemGroup>
    		<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-*" />
    		<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
    		<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.0" />
    		<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
    		<PackageReference Include="System.Runtime.InteropServices" Version="4.3.*" />
	</ItemGroup>
  	<ItemGroup>
		<ProjectReference Include="..\ProjectB\ProjectB.csproj" />
  	</ItemGroup>
  	<ItemGroup>
    		<RdXmlFile Include="rd.xml" />
    		<IlcArg Include="--stacktracedata" />
  	</ItemGroup>
</Project>

Command used to build:

dotnet publish /p:NativeLib=Shared -r win-x64 -c release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions