Add project.json package references to a VSIX
Asked Answered
H

1

37

When trying to add references to a VSIX, it normally pulls it from the references in the .csproj. However, if the references are not in the .csproj, because they now are in a project.json file, then they don't get pulled to the vsix. The solution then may compile, but then the extension fails with "file not found" errors when installed into Visual Studio (since the assemblies where not copied to the VSIX).

I tried with the section of the manifest like so:

<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="*PROJECTNAME*" Path="|*ASSEMBLYNAME*|" AssemblyName="|*ASSEMBLYNAME*;AssemblyName|" />

But it does not work, as it does not recognize the package references.

After some research I saw a similar issue with a PCL, however, without an answer and not the same type of problem: MEF With Portable Class library using Microsoft Composition MEF2 throws file not found exception

In the same note, this seems like an acceptable workaround: VSIX with Project Templates and NuGet Packages however, as far as I understood, it implies using the package during the installation. Besides that, it doesn't work for our case as they need to specify the package version and we are using project.json so we can use floating versions (ie: 2.0.*)

Is there a way to reference this project.json references that we are missing? Maybe a workaround? The solutions I have found seem to all require to "paste" de DLL somewhere, which for floating versions is not that convenient.

Thanks in advance for any help or input.

Edit/Update: Since VSIX automatically pushes any assembly referenced in the CSPROJ (and not the project itself), trying to get the DLLs at a project level seems unlikely. After many tries, I think that a valid workaround would be to get the assemblies from the Output Folder. However, to my knowledge, VSIX does not have a way of doing this, or does it?

Headgear answered 21/6, 2016 at 11:10 Comment(5)
Its weird this's getting so many upvotes. Shouldn't the workaround here be: not to use project.json in the first place? project.json is being dropped in the next few months and Microsoft will start working on moving project.json’s functionality back into good old csproj. Why are you using project.json? Do you need dotnet core on a Visual Studio extension? How? Why? So many questions!Gabbert
[Had this backward in my previous comment, which I deleted] In our case, we were trying to deal with the fact that VS 2015 update 3 uses an older version of System.Collections.Immutable than Roslyn does, so we came across this article explaining how to downgrade the version of that assembly to 1.1.37 in order build an extension that uses Roslyn. At that point, we started running into the issue that DLLs aren't deployed with the VSIX package and found this SO question with the same scenario.Aspirator
FWIW I heard project.json was reverting back to project.xxproj - see this blog post blogs.msdn.microsoft.com/dotnet/2016/05/23/…Alunite
What is the use-case here? You're trying to install a project template via a VSIX and what it to install some packages from packages.json?Busload
I'd either try adding the missing assemblies to the VSIX file in some post build step (you can easily do that in powershell, as the VSIX file is just a ZIP file), or make some pre-build step that fixes up the floating assemblies so that they are referenced in your project. The later seems more sensible to me, as I don't like modifying VSIX file. Sounds like it's going to be pretty unpleasant however you solve it.Ginzburg
B
1

I'm not sure I'm understanding your question correctly, but if you're trying to install a Project Template via a VSIX and you want the project template to include all it's nuget packages when you use it you could do something like this.

Edit your Project Template's xproj file and add the following lines:

<ItemGroup>
    <None Include="project.json"/>
    <None Include="project.lock.json"/>
</ItemGroup>

Edit your Project Template's vstemplate file and add the following lines in the Project node:

<ProjectItem ReplaceParameters="true" TargetFileName="project.json">project.json</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="project.lock.json">project.lock.json</ProjectItem>

That should be all you need to do. Now when you install the project template, then create a new project using that template it should include all the nuget packages that were in the project.json file.

Busload answered 28/12, 2016 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.