wouter de jong wouter de jong - 4 years ago 156
C# Question

My Visual Studio makes an .exe file instead of .dll

I was following this tutorial, but at step 5 I had to import a .dll file in PowerShell:

PS> Import-Module .\bin\Debug\PowerShellModuleInCSharp.dll


But my Visual Studio program only makes an .exe file. I tried importing the .exe file, but this gave an error


Import-Module : The extension '.exe' is not a valid module extension. The supported module extensions are '.dll', '.ps1', '.psm1', '.psd1', '.cdxml' and '.xaml'. Correct the extension then try adding the file 'C:\users\wouter\documents\visual studio`.


So is this because I am making a Windows application instead of an console application in Visual Studio?

This is how my
Debug
folder looks like:

Screenshot of debug folder content.

hvd hvd
Answer Source

No, you weren't following that tutorial. Quoting that tutorial (emphasis mine):

Step 1: Create a Visual Studio project

Within your Visual Studio solution, you will house your cmdlets in a project, just as you would any other component you are building. For PowerShell, create a Class Library project so that once you have built the project, you have a DLL that comprises your PowerShell cmdlets.

The project you created was not a class library project. You appear to have created a Windows Forms Application project instead.

While it's possible to fix this, it involves more than simply changing the project type to "Class Library". The Windows Forms Application project template contains a lot of things you neither need nor should want. It contains references to assemblies you don't want. It contains a form. It contains program start-up code. All of that will remain if you simply change the project type, and you would need to get rid of it manually. It's easier to start over, taking care to follow the steps of the tutorial exactly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download