Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NuGet packages referenced via PackageReference don't include DLLs in VSIX #5899

Closed
AlexEyler opened this issue Sep 15, 2017 · 11 comments
Closed
Labels
Milestone

Comments

@AlexEyler
Copy link

AlexEyler commented Sep 15, 2017

Summary

When building a VSIX that references NuGet packages, users used to be able to easily include the assembly included in the NuGet packages by setting to true on the reference. The VSSDK build tasks search through the @(ReferencePath) item for any reference that has CopyLocal set to true and then includes
those references in the VSIX.

PackageReferences don't give the option to the user to set CopyLocal to true, so it's difficult for the average user to get a NuGet reference included in a VSIX.

I've attached a binary log from a build of a VSIX that's created via the repro steps. Let me know if you need any info - we're willing to make changes in the VSSDK to support this if need be (as long as the changes are backwards compatible, of course).
msbuild.zip

Repro steps

  1. Create a new VSIXProject
  2. Make sure "PackageReference" is enabled by default by selecting Tools > NuGet Package Manager > Package Manager Settings.. and setting "Default package management format" to "PackageReference".
  3. Right click on the VSIXProject and select "Manage NuGet packages"
  4. Add a NuGet package that has a DLL (e.g. NuGet.VisualStudio).
  5. Build the VSIXProject.
    Expected: NuGet.VisualStudio.dll is included in the VSIX.
    Actual: The VSIX does not contain NuGet.VisualStudio.dll.

Workaround

A workaround is available for VSIX developers:

<Target Name="IncludePackageReferenceDependencies" AfterTargets="GetVsixSourceItems">
  <ItemGroup>
    <VSIXSourceItem Include="@(ReferencePath)" Condition="$([System.String]::new('%(ReferencePath.FusionName)').StartsWith('NuGet.VisualStudio'))" />
  </ItemGroup>
</Target>
@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Sep 15, 2017

I talked to alex offline about this, and it seems that the VS SDK needs to also start looking at ReferenceCopyLocalPaths item groups (which is also the item group that the target _CopyFilesMarkedCopyLocal used to copy these references the output directory) . The items won't have CopyLocal set to true (for some reason I can't understand) but as the name suggests , anything in ReferenceCopyLocalPaths is meant to be treated as CopyLocal= true.

The VS SDK would be a better place for this fix.

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Sep 15, 2017

Tracking bug for DevDiv internal bug #453911
update (via rob): ( currently milestone = 15.6)

@rrelyea rrelyea modified the milestones: 4.5, 4.6 Oct 18, 2017
@smourier
Copy link

FYI, I'm facing the same issue (I don't quite understand if it's supposed to be solved as of today), and I used another workaround (the one posted above included ref assemblies, not the real meat, at least for me). I'm running VS 15.5.4, for example:

<Target Name="IncludeNuGetPackageReferences" AfterTargets="GetVsixSourceItems">
  <ItemGroup>
    <VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Microsoft.Win32.Registry'" />
    <VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.CodeDom'" />
    <VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.Configuration.ConfigurationManager'" />
    <VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.ServiceProcess.ServiceController'" />
  </ItemGroup>
</Target>

@AlexEyler
Copy link
Author

Thanks @smourier. This isn't fixed yet, but it's on the backlog. That workaround looks appropriate.

@ghost
Copy link

ghost commented Jun 4, 2018

The workaround is NOT appropriate. For even the simplest VSIX project, there are over thirty packages that are pulled in. You can not expect developers to manage that in the .CSPROJ file manually as a workaround.

@ghost
Copy link

ghost commented Jun 4, 2018

This issue has nothing to do with packages.config (PC) to PackageReference (PR) Migration. You can reproduce the problem using a package.config as well. VSIX just seems to be brain damaged when trying to use NuGet packages.

@UlyssesWu
Copy link

UlyssesWu commented Jun 8, 2018

I'm still facing this issue in VS15.7.3. Can't believe it exists for such a long time.

BTW, the workaround @smourier provided works. I just saw @Dark-Bond 's answer on stackoverflow and you warned @smourier 's answer is invalid. But you have misunderstood the "VS15" is actually VS2017 rather than VS2015.

@alexdrl
Copy link

alexdrl commented Oct 3, 2018

The workaround stopped working in VS 15.8. The System.ValueTuple that comes from a transitive dependency does not get copied with the workaround. A workaround to this is to add a PackageReference to the System.ValueTuple NuGet to the VSIX package Project.

@ceztko
Copy link

ceztko commented Jul 28, 2020

I'm using VS 16.6.4 and I'm finding the same exact issue. The promised version for the fix was 15.6. Since this was declared an external issue, can you state better which is the external VS component bugged here so maybe we can track it in the right place?

@javierdlg
Copy link

javierdlg commented Aug 26, 2020

@ceztko can you try using this workaround?

<Target Name="IncludePackageReferenceDependencies" AfterTargets="GetVsixSourceItems">
  <ItemGroup>
    <VSIXSourceItem Include="@(ReferencePath)" Condition="$([System.String]::new('%(ReferencePath.FusionName)').StartsWith('NuGet.VisualStudio'))" />
  </ItemGroup>
</Target>

Just replaced the NuGet.VisualStudio part with Microsoft.VisualStudio or the namespace of the nuget dll

@lennartb-
Copy link

@javierdlg Thanks, this works for me. Should be noted that this has to be added to the csproj, not the vsixmanifest as I tried at first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants