Using multiple analyzers in Roslyn - c#

I have done a lot of searching around before asking this question. I am new to developing diagnostic tools and code fixes using Roslyn. I am currently using the Visual Studio 2014 CTP. I have been able to successfully create my first code fix tool. However, when I create another tool in a new solution, it still shows up the Description and fixes for the old diagnostic tool.
Can anyone please explain to me what I am doing wrong? I am rebuilding the solution before I test it out, and as far as I am aware, I am keeping both solutions completely separated. Or can anyone tell me how I can use multiple rules in one solution?

Building the .vsix project created by the templates will install a vsix extension into a special VS hive. These are not automatically uninstalled, so go to Tools | Extensions to uninstall them as necessary.
As SLaks mentioned, you can have multiple diagnostic projects in your solution, but you'll have to update the vsixmanifest in the vsix project to include this new project. If you want the multiple diagnostics to always be distributed together, then just put them in the same project (copy the class structure & exports from the sample).

Related

ReSharper and StyleCop.Analyzers

I installed the ReSharper plugin StyleCop by JetBrains to include StyleCop directly into all of our projects, without the need to have the same settings.stylecop or stylecop.json file in multiple projects (since our guidelines are basically identical for all of our projects).
I ran into an issue regarding StyleCop and after posting an issue on the Github page of the plugin I got told that I should use StyleCop.Analyzers since the plugin has been discontinued.
Now I have the following problem. Do I need to explicitly include a corresponding stylecop.json file within each of our projects to make StyleCop work with the newest features? Or is there another way to tell ReSharper to use a default StyleCop configuration for all of our projects? I know it's not that big of a deal to add a file to a project. But it's a little bit tedious to have the same file within ~50ish projects and then change a single thing. Therefore it would be amazing to configure it in one single location.
The StyleCop.Analyzers NuGet package works with or without ReSharper. It will give you far better control over which projects it should apply to. You can configure it by right clicking the rules under Dependencies->Analysers->StyleCop.Analysers in your solution explorer:
Once you change any configuration it will create a .editorconfig file for you which you could use to copy to all of your other projects if required.

C# code snippets not working after VSIX install

We've created a number of C# code snippets. If I import them directly using the Code Snippets Manager they work perfectly as intended.
Since we are going to have people rolling into our project at different moments in time we want to ease the on-boarding process so we want to include these snippets into a VSIX project. For that purpose I followed this process to the letter.
Now there are several issues going on:
1. When I run the VSIX in debug mode I get the experimental instance of visual studio but the scripts' folder is not in the manager and the package does not seem to be installed when I look in the "Extensions and updates".
If I close VS and run the VSIX installer, after re-opening VS I can see the package installed in "Extensions and updates", I can see the custom scripts' folder in the scripts manager and all the scripts are there but, when I open a code file and try to use them they are just not available, the short cuts are not recognized and the scripts are not available in the insert script context menu.
We have tried both approaches in three different environments and the behavior is the same.
We are using Visual Studio 2017 with .Net Framework 4.7.1
I have tripled checked all the settings, made sure there aren't any typos, all the files that need to be added are there in the right place so I do not know what else to check or try.
I am sorry that I do not include any code but there are some things that are deemed confidential but I tried doing it with the Hello World example and I got the same result.
Thank you for any help you can provide.
So as it turned out, there were multiple causes for this behavior.
Environment 1: With the brand new instance of Visual Studio 2017 there was a folder in the Snippets Manager named %LCID%. Within this folder there were two snippets specifically for MVC 4 applications. We do not know why but either these snippets or the folder was preventing our custom ones to be detected, once we removed this folder everything started working as expected.
Environment 2: This environment did not have the %LCID% folder but had ReSharper installed on it and it was configured to use the IntelliJ keyboard schema. As soon as we changed it to use the Visual Studio one then the snippets became available.
Environment 3: In this one the %LCID% folder was not present and the ReSharper keyboard configuration was set to Visual Studio. We disabled ReSharper and the snippets would still not be available. We basically were never able to figure out why the snippets were not available so we ended up going to the file system, cutting them from the custom folder and pasting them under the "My Snippets" default one and they became available.
Hopefully this information will be useful for someone or, even better, somebody might be able to explain why situations one and three would cause the snippets to not be available.

Missing DLL's and Custom Actions when using MSBuild to build Visual Studio Solution with InstallShield Pro Project

I am currently trying to automate our .NET builds and have currently run into a snag. When building the project in Visual Studio on a machine with a InstallShield 2016 Professional License, everything builds fine. However, when trying to use MSBuild to build the VS Solution on a machine with InstallShield 2016 Standalone, the resulting MSI does not have a required DLL or a Custom Action. Meanwhile, trying to build the .ism using Iscmdbld results in the inability to find the Primary Output of the csproj's, Even after building in Devenv
If you are using project output groups (like Primary Output), your choices are limited. You have to use either the VS integrated build (via devenv), or MSBuild; iscmdbld is unable to resolve project output groups.
Your other alternative is to change from project output groups to using static (or dynamic) file links that don't require Visual Studio's knowledge. I tend to prefer static links, as it's easy to tell exactly what's in the project. More importantly, with static links you can't silently lose files that you'd previously added, thus it's easier to avoid potentially breaking component or upgrade rules.
Hopefully, this isn't too old to be of use. InstallShield is the absolute worst, I know.
If you edit your .isproj in a plain-text editor, you'll see that it's just a regular MSBuild script. You'll see that there is a lot of commented out stuff that explains (poorly) things you can add to it. Find the ItemGroup that contains the explanation about "ProjectReference items" and add a node of the following form:
<!-- The ProjectReference items refer to any Visual Studio solutions you want to automatically probe for Project Output Groups. -->
<ProjectReference Include="..\Path\To\Your\Proj.csproj">
<Project>{2d3f37cc-0e93-4673-a3df-59c556185f71}</Project>
<Name>Name Of Project As It Appears in VS</Name>
</ProjectReference>
After adding the above to all of my .isproj files, my automated build worked fine. Why the idiots at InstallShield never saw fit to add this capability to the UI, I'll never understand.
Unfortunately, I don't have any answer to the Custom Action problem, if it's not related to the above.

Automatically add NuGet dependencies and using statements in Visual Studio Code?

I am using Visual Studio Code to develop an ASP.NET 5 application on Mac. In order to use new classes (framework or third-party) in my .cs file, I need to
Manually add a NuGet dependency in project.json and then
Manually add a using statement to my .cs file.
It seems that there should be a better way to import new functionality that doesn't involve searching for the right NuGet and the correct namespace. Any suggestions?
Well, once I got my IntelliSense issues figured out (Visual Studio Code on Mac), I don't have to type using statements anymore. OmniSharp-based IntelliSense is smart enough to suggest (Cmd + . on Mac) adding them for me:
I still have to add a NuGet dependency manually, but I think this is the default behavior in the full Visual Studio too and you need ReSharper to get smarter than that.
Unfortunately, as far as I know of, the short answer is no.
Visual Studio Code is meant to be a light weight editor, so does not have support for the kind of feature you are describing out of the box. The full Visual Studio on Windows does have support for that. When you type the name of a class/type you want to use, eg. JsonConvert, it will detect that the missing type is available on NuGet and offer you the ability to download the correct package and add the using statement. (In the screenshot I already have the NuGet package installed, so it only needs to add the using statement)
This feature is available in the Community edition of Visual Studio, which you can download for free from the visualstudio.com website.
This does require you to run Windows, so I'm not sure if you consider this an option.
Now on the wishful thinking side: VS Code does support extensions these days and it has the power of the Roslyn engine, so theoretically someone could write an extension that will offer this functionality in the future.
You could also try getting it added to the core editor, by opening an issue on GitHub: https://github.com/Microsoft/vscode/issues
I'm afraid neither of these will really help you in the short term though.

Include missing dependencies in VSTO setup

I created a basic install for my VSTO Excel plug-in by publishing my project.
It pretty much worked ok except for some reason it missed 2 dependencies, dll's which are needed to communicate with our SAP system.
Did loads of Googling but I can't find a way to add them in Visual Studio.
I tried downloading the setup project type from MSDN, but wierdly when I built the install it included the SAP dll's but it didn't install my plug-in! There doesn't seem to be much info on how to do this with VSTO, or at least I couldn't find it.
However I note from MSDN that there are a lot of problems with that template, so it's possible it doesn't work for VSTO stuff.
So, a workaround is obviously to run both - and that works ok - but it isn't ideal and (understandably) not satisfactory for our support team.
I would think there are several ways to fix this problem, so if anyone could answer one or two of the following that would really help!
How can I make sure that my dependency files are included in my setup when I use Publish?
What is the correct way to create a Visual Studio 2013 Installer Project
that works correctly with VSTO?
This looks like an answer to question 2:
https://msdn.microsoft.com/en-us/library/ff937654.aspx
1.How can I make sure that my dependency files are included in my setup when I use Publish?
You need to add them as a content to the target folder or make sure that files are copied to the output folder with the add-in assembly. Right click on the reference in the Solution Explorer window and see the reference's Properties. Pay special attention to the Build Action, copy to the output folder properties and etc.
2.What is the correct way to create a Visual Studio 2013 Installer Project that works correctly with VSTO?
The Deploying an Office Solution by Using Windows Installer article describes all the required steps for deploying Office add-ins.

Categories

Resources