include c/c++ unmanaged code dll, consumed using d

2020-06-29 23:32发布

问题:

How does one include in a c/c++ unmanaged code dll, consumed using v2 .net core compatible DllImportAttribute statements, in azure functions publish process?

I've confirmed it works in cloud deployment by manually copying, via azure storage explorer, to functions app storage account | file shares | | site/wwwroot/bin folder.

Issue is now I haven't been able to find way to have it included in vs17 | | Publish process.

Tried placing dll in \bin\$(Configuration)\netcoreapp2.1\bin folder before executing vs17 | | Publish but doesn't result in it being picked up.

回答1:

In VS, right click on your Function project and Edit <FunctionProjectName>.csproj. Add items below to copy dlls we need when publishing or debugging locally.

  <!-- For publish -->
  <ItemGroup> 
    <None Include=" relative or absolute path to your dll, which is not in your project">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <!-- If you have put dlls under your project root -->
  <ItemGroup>
    <None Update="YourDllName.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <!-- For local debug -->
  <Target Name="CopyToBin" BeforeTargets="Build">
    <Copy SourceFiles="relative or absolute path to your dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>