I am getting this conflict every now and then, the spaces(....) are shown as a tab(->) when I am changing something in code. I am attaching an image, where I compared my file with the previous one. If anyone encountered with same error please let me know.
Conflict Image:
You can either change to an external comparer, one that can be configured or setup the code formatting in visual studio to adhere to the project formating guidelines whatever they are.
To configure the Visual Studio, just go Tools --> Options --> Text editor --> All languages (or the one you are using) --> Tabs and change the settings to whatever behaviour works for you.
You seem to have the editor tool configured the use tabs instead of spaces.
How you can control this in VS is answered by https://stackoverflow.com/a/51922994/3906760.
There is, however, another way how this could be controled from "the outside". There is editorconfig (you can spot this, if there is an .editorconfig file your repository), then on save the files will be converted automatically. This is also a way, to consistently push the coding rules to other developers.
Related
I am trying to cleanup/refactor a legacy C# solution and am therefore exploring options how certain refactorings or quick actions could be applied for the entire solution.
For example, Visual Studio 2017 offers 'Replace xxx and xxx with property' and 'Use auto-property' actions, which I can apply via the lightbulb icon for individual classes and methods/properties.
How could I apply these to the entire application or semi-automatically iterate all occurrences (300+) and apply these?
I am open for all options - command line, powershell, VBA, even VISX-development.
I do not want to re-develop the refactoring itself and I don't think that a simple find&replace will do either.
When the quick action window is visible, you can apply the selected fix to the single instance, or across the entire document/project/solution:
If you apply each identified fix across your solution (or project) then you should only need to process each suggestion once, as the first one you change will apply to all further instances.
Alternatively, you could use the dotnet Format tool to apply a set of specific formatting rules to your project via the command line, although this depends upon you having an editorConfig file with your rules defined.
Have a look at the EditorConfig. What you're looking for is the Language Conventions topic and you can flag an action as silent (synonym for refactoring in v15.8):
# $slnRoot\.editorconfig
[*.cs]
dotnet_style_prefer_auto_properties = true:silent
Then when you run across that action in your code, you can apply the quick action to your entire solution, file, project, etc.
Note: there have been some bugs with EditorConfig in VS2017. I've had to close the solution and restart the IDE to get changes to take sometimes.
I often get blue question marks on files in my VS2012 Solution Explorer when opening a solution bound to Perforce through P4VS.
Looks like something is having trouble to "synchronize" with the depot/workspace/whatnot. Hitting "Refresh View" always solves the issue but I'm growing tired on doing this everyday:
This is my VS version:
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
And P4VS:
2014.1.85.4506
This is persistent across P4VS versions for a few months now, and seems to be affecting sometimes individual files, sometimes entire projects, with no apparent pattern.
How can I diagnose what's going wrong, be it a server issue, a VS issue, a workspace issue?... The Perforce Source Control output shows nothing special.
Actually it's not entire folders, it's entire projects. It appears that even if refreshing a project "fixes" the issue for one run, re-opening the solution brings it back. Whereas I think that for individual files, refreshing them solves the issue once and for all. I'll play with it a bit more to confirm that.
To help diagnose what is going wrong you should probably turn on logging, and check the preferences that will show everything in the output window. For the P4VS log, go to:
Tools- > Options -> Source Control -> Perforce - Logging
(This is not the same thing as the Visual Studio Activity log.)
There could be a possibility that you are getting disconnected and refresh reconnects you. I am not sure if you have your connection set to use solution-specific settings, since you did not mention the connection dialog coming up.
This "solved" the issue for me, at least for the entire projects that went blue-question-marked:
1) Tools > Options
2) Source Control
3) Perforce - General
4) Tick the option "Treat Solution/Project as directory when
selected"
Not sure why but that's one less annoyance for me every day. Thanks to Perforce support for suggesting that.
The file is probably not marked for version control. I noticed this icon in one file and opened Perforce to check. For whatever reason, this file was not marked for add in Perforce. After marking the file for add and submitting, the blue question mark went away.
In C# you can have conditional compilation by using macros similar to the C/C++ syntax. This would enable the following to happen:
#define MYMACRO
....
#if MYMACRO
//some C# code logic
#else
//some other C# code logic
I need to define some macros in a dedicated file in a C# library project, and I need these macros to be visible inside the entire library, once defined. The problem is that the above code works only for a single file.
Another way I know to work around this, is to add the macros to the build command. This would take care of defining the macros for the entire .dll and I will have the #if - #else checks working wherever I want inside the library. The issues with this approach is that I want to be able to maintain the macros easily. Having them in a file inside the project will be perfect. I'd like to have some comments inside too, so that I will know what each macro is doing. This will not be applicable if I have to pass the macros as build parameters. Another reason is being able to turn a macro on/off by simply commenting it and examining the behavior.
Is there a decent way to achieve my requirement? I'd prefer not to deal with any build automation tools like MSBuild, NAnt or anything like this, still if no other way is possible I'd appreciate an advice which one you consider a better choice.
You #define them for an entire project with Project + Properties, Build tab, "Conditional compilation symbols" setting. This sets the <DefineConstants> element in the project file. You override this property with msbuild by giving it the /property:DefineConstants="MYMACRO" command line option.
I'd also advise putting the macros in the project settings (csproj file) as #Hans Passant suggests.
If you need the defines documented, you could add a documentation file to the solution explaining what the settings mean.
If there aren't too many variants, you could define a new project configuration for each one. That will allow you to pre-configure the necessary list of #defines for each variant, and then simply switch between them from the configuration combo box in the toolbar. If you want to temporarily disable one option, you could duplicate the current configuration and remove the #define, then delete the config later when you've tested it.
The next option I can suggest to make it "easier" (by combining the settings and docs into a single file as you've suggested) would be to use a simple text file (settings + comments) to configure the project, and spend 15 minutes writing a quick c# app to read this file and write the settings it contains into the .csproj file - it's just XML so should be a trivial app to write. You'd be able to easily tweak this file and run your updater app to chnage the project settings. If it's something you will do often, spend 30 minutes on it and add a UI with checkboxes to choose the settings more easily.
The concept you're describing sounds rather odd, though. The point of a library is usually that you have one standardised lump of code that can be shared by many clients, so changing these sort of defines to reconfigure the whole library a lot is not something that I'd expect to need to do very often. Perhaps you have good reasons, but it may be worth reviewing why you need to solve this #define problem.
(e.g. If you have lots of customers who need different variants of the "library", the best approach will be to use configurations (described above) to allow you to build all needed variants in a batch build. If you are just trying out lots of different algorithms/techniques then can you redesign chunks of the library so that you can restrict the impact of most #defines to just to a single .cs file so they no longer need to be global? Perhaps the library shouldn't be in a single dll, or a plug-in architecture is needed to allow you to pick and choose the "modules" that are included within the library)
C# “preprocessor” directives don't work the same as C preprocessor directives. The most important difference for you is that there is no equivalent of #include. It's not needed under normal circumstances, because C# doesn't have (or need) header files. I don't think what you want is possible, unless you somehow create your own preprocessor or read the file with #defines and make them into parameters of msbuild.
But I think it would be easier for you to use more object-oriented approach: encapsulate the different approaches into classes and use them. To specify which one of them to use, you could use dependency injection. That means you would have to ship a DI library along with your library, but I think that's a price worth paying.
Also, this approach would alleviate a problem with conditional compilation: specifying different set of symbols may break the build in unexpected ways.
Using GUI
Open the project in Visual Studio
Right-Click on the project file in the solution explorer go to properties
Go to Build tab and Make sure you select the All Configurations in the configuration drop down
Make sure selected the All Platforms in Platform drop-down
Type the Preprocessor Definitions you want in the Conditional Compilation Symbols text box separated by semicolon
To the Project file
Open the project file in a text editor
Copy and paste this code to end of existing PropertyGroup
<PropertyGroup Condition="'$(VariableName)'=='VarableValue'">
<DefineConstants>PDEF1;PDEF2;PDEF3</DefineConstants>
</PropertyGroup>
If you not required to add a condition, delete the Condition="'$(VariableName)'=='VarableValue'" part
Save the project file and open from Visual Studio
From: https://codeketchup.blogspot.sg/2018/04/how-to-add-project-level-preprocessor.html
Weird problem, started with migration to Visual Studio 2010.
Some forms, when opened, will have some objects' properties set to a string that is empty in resource file. Most often these are control properties like ImageKey, ToolTipText and for UltraGrid some columns get columnX.Header.Caption set to that string. This will obviously remove set images and give wrong column header texts in other locales. Additionally tooltips will show up in weird places (like tab panel body).
This string (strSaveInterestDetails8 below) is empty in Strings.resx (<value />), but not empty in Strings.fi.resx. When I changed this string to have a space, designer started to use an other "empty" string from Strings.resx..
These forms are all derived from common base, but it does not have anything special/suspicious. Debugging these from additional devenv instance failed, since the debugger never broke on the set breakpoints (thrown exceptions in internal VS code were caught).
example:
ultraGridColumn23.Header.Caption = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
...
this._timespanCheck.ImageKey = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
...
this.tabPage1.ImageKey = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
this.tabPage1.ToolTipText = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
So has anyone run into something similar or has better google-fu?
This is a long standing bug in Visual Studio. Microsoft is aware of the issue, but still no fix. You can vote up the issue here:
https://connect.microsoft.com/VisualStudio/feedback/details/683661/windows-forms-designer-cs-files-corrupt-after-changing-language#tabs
I'm having the same problem, but with VS2008. However, a VS2010 Web Developer Express version is also installed on my system (since a couple of months). First, I was developing in a project that uses multiple language resources and then I opened up another VS solution to change something on a form. The Windows Form Designer replaced all the empty strings in the Designer.vb file with a string resource identifier from the first project!
I could solve the problem by closing Visual Studio and reopen the solution.
In our experience, this is usually a bug caused by the presence of the text string
<value />
in the xml of a resx file. When you edit and save the form designer, all the empty strings "" in the designer file get mapped to the key associated with this self-terminating node.
Theses spurious <value /> entries sometimes appear if you start building a project while the resource editor has still got the flashing cursor in the 'new row' line, and there is no text associated with the key.
Search the project for <value /> and eliminate them from the resx files. Then clean and rebuild the project, (which will fail), then fix the compile errors by replacing them with ""
Hope this helps.
I think this will work for you. Check the accepted solution.
Or maybe this.
I'm writing an add-in for Visual Studio, which must be compatible with VS 2005. This add-in involves marking certain files as "special", and I'd really like to make their specialness visually apparent in the Solution Explorer - currently my users either have to manually keep a note of which files are special, or right-click on each potentially special file and see what menu items are there.
Ideally I'd like to change the icon, but I'd be happy to (for instance) make the file's name bold or something.
Unfortunately, all the appearance-related methods seem to live on Microsoft.VisualStudio.Package.FileNode, and I only have access to UIHierarchyItems and ProjectItems. I've spent several days grovelling through MSDN, and I can't find any way of constructing a FileNode given a ProjectItem or UIHierarchyItem. There's a suggested solution on the MSDN forums, but it assumes you're starting with a FileNode, and as far as I can tell this implies creating a custom project type (and presumably some sort of project-conversion system). I don't think my users would be too happy with this.
Or is there something I'm missing?