Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Question - Using .NET Standard 2.0 libraries in VSIX projects #465

Closed
jp2masa opened this issue Aug 23, 2017 · 5 comments
Closed

Question - Using .NET Standard 2.0 libraries in VSIX projects #465

jp2masa opened this issue Aug 23, 2017 · 5 comments

Comments

@jp2masa
Copy link
Member

jp2masa commented Aug 23, 2017

I want to know what is the correct way of distributing a Visual Studio extension with .NET Standard 2.0 libraries.
The libraries I use were targeting .NET Standard 1.5 and I would add references to System.Runtime, System.Reflection,... in the VSIX project, then set ForceIncludeInVSIX metadata to true and the references were included in the VSIX.
After upgrading Visual Studio 2017 to version 15.3 and installing the .NET Core 2.0 SDK, this no longer works, resulting in missing references.
Now I'm upgrading the libraries to .NET Standard 2.0, what should I do to make sure the extension will work? Should I include netstandard.dll?
Currently I'm using this MSBuild target in the VSIX project:

<Target Name="IncludeNETStandardFacadeInVSIX" AfterTargets="ImplicitlyExpandNETStandardFacades">
  <ItemGroup>
    <Content Include="@(_NETStandardLibraryNETFrameworkLib)" Condition="%(Filename) == 'netstandard'">
      <IncludeInVSIX>True</IncludeInVSIX>
      <VSIXSubPath>/</VSIXSubPath>
    </Content>
  </ItemGroup>
</Target>
@weshaggard
Copy link
Member

It depends on which version of .NET framework you are targeting and what your dependencies are. However the snippet you show should select the correct netstandard.dll to include as a dependency.

@jp2masa
Copy link
Member Author

jp2masa commented Aug 25, 2017

I'm targeting .NET Framework 4.6.2. Is netstandard.dll the only assembly that needs to be included in the VSIX?
Also, I have other problem related to the use of .NET Standard libraries in .NET Framework projects: I have a .NET Framework 4.6.2 project (new csproj) with some MSBuild tasks. This project has a reference to a package that depends on System.Data.Common, version 4.1.0. This project has references to some .NET Standard 2.0 projects too. Because of the .NET Standard 2.0 references, System.Data.Common, version 4.3.0 is copied to output. When the assembly is running, I get a FileNotFoundException, because System.Data.Common 4.1.0 is required, but the one in the assembly path is 4.3.0. I'm currently using this workaround:

<Target Name="ExcludeSystemDataCommon" AfterTargets="ImplicitlyExpandNETStandardFacades">
  <ItemGroup>
    <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="%(Filename) == 'System.Data.Common'" />
  </ItemGroup>
</Target>

This way I get the correct System.Data.Common assembly when publishing the project. Is there an easier way of overriding the System.Data.Common package and use version 4.1.0 instead of 4.3.0?

@weshaggard
Copy link
Member

I'm targeting .NET Framework 4.6.2. Is netstandard.dll the only assembly that needs to be included in the VSIX?

It really depends on what the closure of your dependencies contains. If you are only referencing netstnadard2.0 binaries then that is likely enough but if you have any libraries referencing an earlier netstandard version then you might need some more assemblies to complete the closure.

As for your System.Data.Common issue I don't think you really want either of those. In .NET Standard 2.0 that library is included. You might actually need to deploy the System.Data.Common that is in _NETStandardLibraryNETFrameworkLib item group.

@jp2masa
Copy link
Member Author

jp2masa commented Aug 26, 2017

If I just publish the project, I get the dll and the dependencies (netstandard.dll, System.Runtime.dll, System.Data.Common.dll,...), but I need System.Data.Common.dll 4.1.0 and the one that is deployed is 4.3.0, which causes a FileNotFoundException at runtime.

@weshaggard
Copy link
Member

I suspect what you are missing is the binding redirects. See dotnet/sdk#1070. Try setting those 2 properties in your library project.

@jp2masa jp2masa closed this as completed Nov 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants