sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 641 forks source link

v4.0.1 SharpDX.Direct3D11.Effects missing native DLLs from csproj after NuGet Package Install #941

Open andyb1979 opened 6 years ago

andyb1979 commented 6 years ago

Not sure if this is a bug or intentional change to the deployment of SharpDX.Direct3D11.Effects but as requested here, I am reporting.

Details can be found in the following StackOverflow post. There is a workaround there too.

Reproduction: Start a new WPF Project in Visual STudio 2013, or 2015, and using package manager run the command

'>Install-Package SharpDX.Direct3D11.Effects

Expected: native libs are added to the csproject Actual: Native libs are not added

amerkoleci commented 6 years ago

Please try the last 4.1.0 nuget package and see if it fixes it

andyb1979 commented 6 years ago

I just tried it (4.1.0-ci184) and doesn't seem to add the native DLLs to the project.

amerkoleci commented 6 years ago

Native dlls are added to output path not csproj

andyb1979 commented 6 years ago

That's clever! ^_^ Where in the SharpDx code is this setup? I'd love to use something similar for native/managed mixed deployment in my own projects.

amerkoleci commented 6 years ago

https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Direct3D11.Effects/SharpDX.Direct3D11.Effects.csproj from line 21 to 40, if you want to have dlls appearing in your csproj and VisualStudio instead of None Items set them to Content Items.

andyb1979 commented 6 years ago

Trying it now ...

andyb1979 commented 6 years ago

I'm really sorry but doesn't seem to work, or I'm doing something wrong? Have a look at the word doc below. This is what I've tried.

https://1drv.ms/w/s!AjQxIVxoV2Ypg5oVTb6XuN5-a5cchA

Expected: sharpdx_direct3D11_1_effects_x64.dll / x84.dll should be in output folder Actual: Only the .NET assemblies are copied over.

In my main project I get this DllNotFoundException unless I specifically add the native DLLs to the project with 'Copy Always'.

image

xoofx commented 6 years ago

This deployment is only working with .NET core projects. In order for SharpDX.Direct3D11.Effects to support this for standard .NET project, it should have something similar to what was done in SharpScss with the associated target file stored into the nuget package. PR Welcome.

andyb1979 commented 6 years ago

I'd love to contribute but I have no idea how to do that! :? :)

andyb1979 commented 6 years ago

This deployment worked in v3.x of SharpDX. I'm assuming it occurs during the NuGet package install step. However I can't find any *.nuspec files in the repository SharpDX.

Any suggetsions?

xoofx commented 6 years ago

However I can't find any *.nuspec files in the repository SharpDX.

They are generated from csproj. If you follow how it is done in SharpScss, it should be fairly straightforward to add this to SharpDX.

andyb1979 commented 6 years ago

We couldn't understand the SharpDX source / how nuget packages are created, but we fixed this in SciChart.DirectX by using this method:

https://stackoverflow.com/a/44879958/303612

1.) Adding sharpdx_direct3d11_1_effects to files in the SciChart.DirectX nuspec

    <!-- Copy SharpDX Effects native DLLs to output dir always on build https://stackoverflow.com/a/44879958/303612 --> 
    <file src="Lib\net45\sharpdx_direct3d11_1_effects_x64.dll" target="build" />    
    <file src="Lib\net45\sharpdx_direct3d11_1_effects_x86.dll" target="build" />        
    <file src="SciChart.DirectX.targets" target="build" />  

2.) Adding a SciChart.DirectX.targets file which copies these files to output dir always

<!-- Copy SharpDX Effects native DLLs to output dir always on build https://stackoverflow.com/a/44879958/303612 --> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="$(MSBuildThisFileDirectory)sharpdx_direct3d11_1_effects_x64.dll">
      <Link>sharpdx_direct3d11_1_effects_x64.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="$(MSBuildThisFileDirectory)sharpdx_direct3d11_1_effects_x86.dll">
      <Link>sharpdx_direct3d11_1_effects_x86.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

I would've loved to have fixed it in SharpDX and contributed, but I'm afraid I don't understand it well enough, and time constraints -> it got fixed on our side.

maybe you have a contributor who can find the above info useful though.

Thanks and all the best!

Skyppid commented 6 years ago

This is still an issue with SharpDX 4.0.1 and UWP apps. I added the Nuget package but don't have the native assemblies. I don't even know where to get them. Hope this will be addressed in future releases.

stoitchog commented 6 years ago

I don't know how exactly the NuGet deployment works, but the native dlls that the SharpDX.Direct3D11.Effects is trying to load are called sharpdx_direct3d11_1_effects_x86.dll and sharpdx_direct3d11_1_effects_x64.dll respectively. The dlls that are in the package folders don't have the x86/x64 suffixes. Is NuGet suppose to rename them upon deployment? Or maybe this is related to the whole problem?

Alan-FGR commented 5 years ago

I can confirm this, even using .net framework when you install the effects package from nuget you still have to manually grab the files in \packages\SharpDX.Direct3D11.Effects.4.2.0\runtimes\<arch>\native, and add the _x86/_x64 suffixes.