0

I have a Visual Studio Extension project. It works fine, builds into a vsix and does its job. I'm using VS2017

I'd like to unit test it. I already wrote unit tests, using MSTest v2.

Problem is: When I try to build/run the test project, there's an error that it didn't find the myProject.dll, obviously because there isn't one (myProject builds to a .vsix file).

How do I unit test my vsix project?

Edit: Debugging it works fine.
Edit 2: The whole output is the vsmanifest file and a .vsix file. Installing and running works.

Tl;dr of the answer: Can't test a vsix.

Squirrelkiller
  • 2,575
  • 1
  • 22
  • 41

2 Answers2

2

Your test project should be a DLL type of file. After you will change it to "CS" type of file for example, the runner will be able to run your test

  • What do you mean "CS"? The project file is a .csproj, the source files are .cs, packages.config, and the manifest file (.vsixmanifest), and the output is one .vsix file and the manifest file. Which ones do I have to change? – Squirrelkiller Jun 05 '18 at 13:56
  • 1
    I meant that the output type of your project needs to be Class library in order to be testable. You **can't** run test on vsix type of project. –  Jun 07 '18 at 07:59
  • Uhm technically the output type in project properties -> Application is "Class Library". So you're saying it's just impossible to test a vsix project? – Squirrelkiller Jun 07 '18 at 08:03
  • 1
    I just tried to copy your situation, Made a VSIX Project with a unit test project. It says VSIXproject.dll could not be found when I try lunching it with MsTestRunner. I am using typemocks Isolator as a runner by default and it was not able to run it either. To my knowledge, you **cant** unit test a VSIX project. If you can, move your project to a different project framework like 'classlibrary' , it is testable for 100%. –  Jun 07 '18 at 08:33
  • This is not a valid answer. On VS 2015 you can test your VSIX projects using XUnit / NUnit / Basic Unit Tests from Visual Studio. Unfortunately, this way is not possible anymore in the latest updates of VS 2017 and VS 2019. In this moment I am trying myself to find a way to test my own VS Extensions using the latest versions of Visual Studio. – Ionut Enache Mar 27 '19 at 14:45
0

So I just stumbled across this post. The problem is the .dll and .pdb files are inside the vsix package. So to Unit Test, they need to be also outside of it.

This indicates a bug in the imported target in the .csproj file:

<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />

This target is removing the dll and pdb as it builds the vsix. It shouldn't do that. Now, the vsix is simply a zip file with a special name. So we can unzip it.

I added 7z.exe to my solution in a tools folder, and run this in the post build actions:

"$(SolutionDir)Tools\7z.exe" x -aoa "$(TargetDir)$(TargetName).vsix"

Now my unit tests work fine.

Rhyous
  • 6,510
  • 2
  • 44
  • 50
  • So uhh...I kinda left the company where I built the vsix, so now I can't actually try your solution. I'll get back to you when I build another, already have a few ideas for both personal use and use in my new company. Thanks for providing an answer that seems to provide more chances than the other one :D – Squirrelkiller Mar 17 '19 at 18:30
  • I submitted a problem report to Microsoft as well. We'll see where that goes. Best case is that they fix the target to also leave a copy of the dll and pdb there and then we don't need a hack to unzip. – Rhyous Mar 18 '19 at 19:34
  • Or they make msbuild/dotnet smart enough to recognize a vsix as their own and unpack on the fly. Or, well, black magic. – Squirrelkiller Mar 18 '19 at 20:38
  • Hello, I stumbled over your question and this answer. I appreciate your mentioned approach, and I have an idea to automate it via MSBuildTaks. Do you have a issue report ID/URL that I could keep track of it by my own? I'm interested in a clean solution, in best case from Microsoft itself, as well. – ChW Aug 17 '21 at 14:55
  • https://developercommunity.visualstudio.com/t/project-template-wizard-dll-missing/495515 – Rhyous Aug 18 '21 at 16:16