This is a scenario I identified when we turned on Stylecop rule SA1210 in our project.
The below is the set of using in one file I tried this sorted by visual studio's Remove and Sort usings.
I have configured to use System Directives first. Also, I have configured to automatically sort usings on file save.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using Bss.Cloud.Api.Caches.Redis;
using BSS.Angel.BusinessEntities.Cache;
using BSS.Angel.BusinessEntities.Lists;
using BSS.Angel.BusinessEntities.Repositories;
using BSS.Common.DataAccess.Claims;
But the above raised Stylecop SA1210.
When I use VS's intellisence's auto fix, I get
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using BSS.Angel.BusinessEntities.Cache;
using BSS.Angel.BusinessEntities.Lists;
using BSS.Angel.BusinessEntities.Repositories;
using Bss.Cloud.Api.Caches.Redis;
using BSS.Common.DataAccess.Claims;
The reason being Cloud > Angel.
This makes it difficult for me as when I save, It gets sorted back to the old VS' Sort Using way.
Their reason being BSS > Bss according to Visual studio.
Now I cannot save the SA passing way(I have automatic sort enabled). VS does not support style cop way.
We cannot update the BSS to Bss as this is a huge change in a different library project for us.
Is there something I can do for Stylecop to be compatible with Visual Studio and not disable Automatic Sort using on save.
Related
ITNOA
I want to write Kamailio Language Server for Visual Studio 2022, I Create a project in GitHub with below structure
And I use kamailio.tmLanguage.json from https://github.com/miconda/vscode-kamailio-syntax/blob/master/syntaxes/kamailio.tmLanguage.json that I sure works for Visual Studio Code, So this grammar is correct
But I do not know why my code is not working correctly and does not highlight keyword?
My test with .kcfg file extension like below
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kamailio.VisualStudio
{
#pragma warning disable 649
public class KamailioContentDefinition
{
[Export]
[Name("kamailio")]
[BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
internal static ContentTypeDefinition KamailioContentTypeDefinition;
[Export]
[FileExtension(".kcfg")]
[ContentType("kamailio")]
internal static FileExtensionToContentTypeDefinition KamailioFileExtensionDefinition;
}
#pragma warning restore 649
}
Any body can find my mistake?
All code to reproduce my problem is in GitHub
The good news:
It seems that all you need to do is add fileTypes to your kamailio.tmLanguage.json file, e.g.
"fileTypes": [
".cfg"
],
VS matches TextMate grammars to files based on these properties.
The bad news:
VS is apparently not smart enough to support other ways to filter when you are or aren't applicable. Specifically, it does not seem to support the firstLineMatch property, so it will apply your grammar to all *.cfg files. If there is another way to filter which files are or are not applicable, I wasn't able to find it.
I am trying to scan all assemblies in a subfolder of my main project and then add the contained registry to my main registry in order to override default registry entries, where necessary and intercept types for dependency injection.
For this I create the following registry
public PluginRegistryAdder(string pluginPath)
{
Scan(x =>
{
x.AssembliesFromPath(pluginPath);
x.LookForRegistries();
});
}
which I plan to add to my main container like this:
var pluginRegistries = new PluginRegistryAdder(pluginPath);
Container.Configure(_ => _.IncludeRegistry(pluginRegistries));
The problem I am now facing is that I get this error, when using AssembliesFromPath and I don't know how to fix it:
System.MissingMethodException: Method not found: 'Void StructureMap.Graph.IAssemblyScanner.AssembliesFromPath(System.String)'.
Googling suggests that I should use the namespace StructureMap.Graph, but this did not solve the problem. Here are my using statements, of which only StructureMap is not greyed out (e.g. marked as not redundant) by Visual Studio (I was trying to find the missing reference, but nothing helped):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StructureMap;
using StructureMap.Graph;
using StructureMap.Configuration.DSL;
using StructureMap.Configuration;
using StructureMap.Graph.Scanning;
using StructureMap.Util;
Any suggestions, what I should try?!
UPDATES:
Note that when I comment out just the line with AssembliesFromPath, solution runs just fine, although LookForRegistries is definded in the same class as AssembliesFromPath.
AssembliesFromApplicationBaseDirectory gives me the same problem.
This problem seems to have been caused by a version mismatch between my DI project and my main project. After some trying I ended up reinstalling the newest version of StructureMap in both projects and the problem went away.
I'm used C# -some- but not recently.
I've got this header from some code, and it calls a custom non-system library, (Dynastream.Fit, at the bottom), but I need to know how to tell the program where it resides so it can compile. Pretty sure the library is in the SDK I downloaded, just need to find it. This is the FitSDK from ANT+.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using Dynastream.Fit;
You need to add the dll of Dynastream.Fit to your project Reference folder by right clicking the reference folder -> add reference -> Browse -> choose the dll; unless you have already installed the assembly in GAC.
I have a Silverlight control i need to convert to WPF
(Yes, i know that's not wise, don't have a choice)
And i am aware that some assemblies need to be changed.
this is a follow up of this question
Now i am kinda sure that i'm missing a big thing here.
DIdn't really know how to do that so i just started copying all the cs files code to new
class project.
Now i get all kind of weirds errors.
Most for assemblies missing ( ofcourse),
Now what i fail to understand is i'm missing very basic stuff and i am calling the right ones i belive. stuff i used in other WPF applications.
for isntance i get Errors for theese classes :
Point, Size, UIElement, DependencyProperty, MouseEventHandler etc.
Now the project is just 14 classes, no main file or anything, could this be related?
Anyway, i'm using this code to call assemblies (preety much the same anywhere):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.Threading;
using System.ComponentModel;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
And the VS isn't givining me on help any assembly i could call, just the option to generate my own class.
I am targeting Framework 4.0 using VS 2010
Help!
Did you put this control in a new WPF project? If you didnt make sure you add these References
PresentationFramework
PresentationCore
WindowsBase
System.Xaml
Then remove all your using Statements and readd them all.
You also may need
System.Drawing depending on what Point you are using
UIElement is in System.Windows and you'll need to make sure that PresentationCore.dll is referenced by your project.
DependencyProperty is in the same namespace but required WindowsBase.dll to be referenced.
MouseEventHandler in System.Windows.Input which is also in PresentationCore.
It might be simpler to create an empty WPF project which should have the basic references set up and then adding the source to that.
we always add namespace at the top of the every form in win apps
like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;
and most of namespace are common in most form but in asp.net there is a provision to add namespace only once in web.config file. so we dont have to add it in all web form and it save time. so i just need to know is there any same sort of provision for our win apps. how to achieve it. thanks
No, there isn't any sort of provision for your WinForm applications as there is for ASP.NET applications using the <namespaces> section in web.config. Also note that this applies only to .aspx pages and not code behind C#. In C# you have to add proper using statements in order to bring the types you want to use into scope.
One method is to add the standard using directives into the common templates.
You don't mention which version of visual studio you are using but in VS2010 you can find the templates in:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
Change the Class.cs file in the zip to include the usings you want by default.
The only downside to this is that it is per machine - so you will need to do it on each developers computer - although I daresay you could roll it out with Active Directory (that's a question for serverfault.com).
I believe it also possible to set up team templates - but it's not something I have tried. More information available here:
http://msdn.microsoft.com/en-us/magazine/cc188697.aspx