Visual Studio Extension, dll deployment and locking [C#, VSIX] - c#

I need some help using CodeAnalysisCSharp in my VSIX project.
The issue I'm currently having is that the necessary dlls are not "deployed" when installing the extension. I've had to manually copy/paste these files to the C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE folder, for it to "work".
System.Numerics.Vectors.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Memory.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.CSharp.dll
I have created an extension project and added a custom command. This command should be able to use the CodeAnalysisCSharp to navigate the syntax tree of a C# file.
I'd very much like for the installer file (.vsix) to be able to deploy the dll dependencies, just like you'd expect it to, I just don't know how or where to look to make this happen.
Thanks in advance.

I found out that if you use the vsixmanifest file to add assets, and give it a sub folder, it doesn't get packaged correctlty. The files will be copied correctly, but the reference to the dlls are not correct, so you get a "dll not found" exception.
In general the vsixmanifest designer, seems to be riddled with quirks where you need to edit the xml code to be sure that the values are set correctly.

Related

How do I create an installer for a class library in VS 2013?

I am hoping to get some help to figure out how to create an installer in visual studio 2013.
My class library project generates a DLL called DataTest. The solution also has an xml file called config.xml. Currently when I build the solution the DataTest DLL ends up in the bin folder (and the config.xml is just a static file somewhere). What I want the installer to do is copy/install the DataTest DLL to C:\MyData\Test and the xml file should end up in C:\MyData\Config.
I have found this http://geekswithblogs.net/TarunArora/archive/2014/04/24/visual-studio-2013-installer-projects-ndash-hello-world-installer.aspx which seems like a good place to start but I don't have much experience with the different configurations in VS so I don't really know how to do what I want to do.
Thanks
I'm assuming you want an MSI file to do the install because you posted that link, so you're using the Visual Studio Installer projects extension.
This might also help, old but still applies:
https://www.simple-talk.com/dotnet/visual-studio/getting-started-with-setup-projects/
Configurations in Visual Studio don't really have much to do with this. The Bin, Release, Debug folders in your build are nothing to do with where you want to deploy the file on the target system. For example, if you have a Dll that you want to install in the Common Files Folder then you select that folder in the File System view of the setup project and just drag and drop the file in there. The same principle applies to the Program Files folder, which is the usual place for applications.

Where is the Stylecop configuration file?

I've installed Stylecop via NuGet. I wish to disable some rules, and I know this can be done via a configuration file from what I've read. However, I can't find the file anywhere, and there seems to be little documentation describing where to create the file.
How do I go about making the file?
Edit: As this question still seems to be getting attention a couple of years later, I recommend using Roslyn Analyzer based StyleCop now.
This has a few advantages:
It's actually maintained and active.
Takes advantage of Roslyn, and can perform some changes for you.
It's a NuGet package so is installed as part of your projects, meaning you no longer need to install the seemingly unmaintained StyleCop Visual Studio extension (that's if you can even find the right place to download it from in the first place!). This way you can enforce code style/conventions much easier in for example OSS.
Automatically creates the .ruleset file for you, and as a result of using Roslyn Analyzers you get IDE support for enabling/disabling rules.
If you installed Stylecop via NuGet (the StyleCop.MSBuild package), then you will not have the folder detailed in the other answers.
You will find the file in your project folder here:
packages\StyleCop.MSBuild.{version}\tools\Settings.StyleCop
You should copy this file to the root of your project.
If you would rather not manually edit the file, there is also a nice gui tool called StyleCopSettingsEditor in the tools folder, which you can just drag your settings file onto.
If you copy the Settings.StyleCop file to the root of the solution, then it will be inherited by all projects. This means it can be kept in Source Control and accessed by any Continuous Integration server you are using.
If you reference and alter the file in C:\Program Files (x86)\StyleCop {{version}}\Settings.StyleCop this needs to be kept inline on each developer's PC. where as copying it to the root of the solution
The file Settings.StyleCop should be located in your install directory, on my machine it's here:
C:\Program Files (x86)\StyleCop 4.7\Settings.StyleCop
You can edit the rule settings by opening this file with StyleCopSettingsEditor.exe, located in the same directory (double-clicking the settings file will do the trick).

How to include other files to the output directory in C# upon build?

I have some library files needed for my application to work.
My application has a setup and deployment included.
I already know that in order for a library file to be added to the output directory of the application when installing, I just have to reference those libraries inside the .NET IDE before building... the only problem is that these libraries can't be referenced... So I need to be able to copy these libraries to the installation directory of my application... At the moment, I am copying these libraries manually...
Addendum
I also did try to add these library files as an Existing Item to my project and marked each library files' Copy to Output Directory to Copy if newer on their properties but still not getting the solution I want.
Update 1
Thanks for you help guys it helped me solve my problem, I managed to make the solutions you posted work except for one... #Matthew Watson's post.. I even managed to find a solution too so I wanted to share it with you also.
Heres what I did:
I opened the setup and deployment project in my application.
Under the Application Folder Tree, on it's right side, I right clicked..
then clicked Add..
then clicked File
and then browsed for the files I wanted to add to the installation directory
and click open.
But out of curiosity...I am still trying to make what #Matthew Watson posted work...
Update 2
I forgot to update this post yesterday, I already manage to make Matthew Watson's solution worked yesterday. Thank you again for all your help guys.
You can add files to your project and select their properties: "Build Action" as "Content" and "Copy to output directory" as "Copy Always" or Copy if Newer (the latter is preferable because otherwise the project rebuilds fully every time you build it).
Then those files will be copied to your output folder.
This is better than using a post build step because Visual Studio will know that the files are part of the project. (That affects things like ClickOnce applications which need to know what files to add to the clickonce data.)
You will also be more easily able to see which files are in the project because they will be listed with the source code files rather than hidden in a post-build step. And also Source Control can be used with them more easily.
Once you have added "Content" files to your project, you will be able to add them to a Visual Studio 2010 Setup and Deployment project as follows:
Go into your Setup project and add to your "Application Folder" output the Project Output called "Content Files". If you right-click the Content Files after adding them you can select "outputs" and see what it's going to copy.
Note that Setup and Deployment projects are NOT supported in Visual Studio 2012.
You can use Visual Studio Post Build Event - Copy to Relative Directory Location. Which are basically scripts that are executed on build of specified project.
So you can use it to copy binaries you need, before actually running your application.

Clickonce and postbackevent

I have a WPF project and a post build event which copy files from a folder outside of the solution into the output directory.
I want to publish my application with Clickonce publish. The only problem is that the copied files are not included in the publish or the manifest.
I tried using MageUI.exe , msbuild /target:publish from the visual studio cmd and even tried to change the project file by hand including a beforepublishevent but none of that worked.
I am open to suggestions, but what I want is to take the output folder and make the installer install the output files. (e.g. install the .net 4 framework and visual c++ runtime libs)
If you don't want them in the solution, but you do want them in ClickOnce then the only possibility is to use an external tool to create the ClickOnce manifests as you can't add non-project files to the ClickOnce output in Visual Studio.
There are two options I know of:
Use MageUI to manage your ClickOnce manifests. You can add additional files to your application in Mage.
You could use some software that I created and sell called ClickOnceMore (www.clickoncemore.net). ClickOnceMore will allow you to add all the files in one directory to your ClickOnce manifests by adding a single folder include. You can also then control which sub folder on the client they get deployed to. It was designed to make scenarios like this simple. You can download a free trial on the web site.
I hope it helps. Apologies for the marketing plug, but I do think ClickOnceMore can solve your problem perfectly.
Instead of copying the files through a post-build event, why don't you include them inside the project, and mark Copy to Output Directory = Copy if Newer?
If they are DLLs, you can add them as reference instead.
There are other options to create installers such as WiX+SharpSetup. It's much more flexible, but also more complicated, and takes more time to create simple installers.

How do I add a folder to a program's namespace?

I recently converted a Visual Studio 2006 project up to Visual Studio 2010. The conversion went over fine, but somewhere along the line the namespace got corrupted, and as a result, parts of the codebase are throwing errors (because the objects they're referencing, etc. are no longer being imported).
I can manually locate the folder with the relevant files, but can't seem to reference the file with using clauses (or I'm botching using entirely). Is there some function in visual studio I can use to import the requisite files directly?
For physical files you can click the Show All Files button at the top of the solution explorer, then locating the folder, right click and choose Include in Project.
if you can get Resharper installed, it will try to hint you the namespace. if upgrade missed to add some files, then you should add them manually and recompile. i am not sure if you can requisite the files directly
The using directive has nothing to do with the folder where the file is located, it is only depending on the name after the "namespace" keyword inside each file.
In some projects people name their namespaces similar to the folder structure but to the c# compiler that is just a coincidence.

Categories