FileNotFoundException when adding a Nuget reference to my Visual Studio Extension

80 Views Asked by At

Update The Visual Studio Extension targeting .Net 4.8, and Fluxor supports that framework.

I have a Visual Studio Extension project (.net 4.8). I've added a NuGet package reference to Fluxor, but as soon as I reference any type within that class library I get the following exception

System.IO.FileNotFoundException: 'Could not load file or assembly 'Fluxor, Version=5.9.1.0, Culture=neutral, PublicKeyToken=6e6412da1d5ce8eb' or one of its dependencies. The system cannot find the file specified.'

public sealed class FeatureExplorerPackage : AsyncPackage
{
    protected override async Task InitializeAsync(
        CancellationToken cancellationToken,
        IProgress<ServiceProgressData> progress)
    {
        await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

        InitializeState();
    }

    // Exception is thrown when trying to step into this method
    private void InitializeState()
    {
        IStore store = null!;
    }

Can anyone tell me how to fix this?

2

There are 2 best solutions below

1
Hans Karlsen On

I thought this was really silly - but the only way I could get it to work:

You cannot refer to NuGets your templates are going to use - you need to include them in the VSIX.

I am not sure that this is the culprit in your case - but try and include the whole nupkg as content and mark "Include in VSIX" like the image shows:

enter image description here

0
Peter Morris On

Mads Kristensen answered on Twitter. The DLLs are added to the VSIX automatically, but I needed to add the following lines of code to give VS a hint.

[assembly: ProvideCodeBase(AssemblyName = "Fluxor")]
[assembly: ProvideCodeBase(AssemblyName = "Morris.Reducible")]