Insert or replace Copyright Policy in every page on VS-2010 - visual-studio-2010

I have more then 1000 pages in my project.In every page of my project I have Copyright Policy.Now terms of policy is change so I must have to open each and every page to paste my policy.Its so boring process and chance to missing some file.Find and replace all in entire solution not help much in this situation.So Is there any built in method in VS2010 to solve my problem ? Or is there any other alternative solution.Thanks.
Old One:
#region "Copyright"
/*
Old Copyright
.........................
*/
#endregion
replace with New one:
#region "Copyright"
/*
New Copyright
....................
*/
#endregion

It shouldn't take long to write another quick program in C# to read in your source files and replace the comment. Or if you're lucky enough to use Resharper, it has a code cleanup feature that can add or update headers in source files.

Although you could, you don't need to write a macro or other text-processing script to do this. Just use the "Find and Replace" feature built into Visual Studio.
You have a specific "old" format that you're replacing, down to the #region "Copyright" and #endregion lines that enclose the block, so this should be rather simple. "Find and Replace" even supports regular expressions.
Only problem is that Visual Studio (at least up to VS 2010, not sure if this changed in 2012) uses its own regex syntax. Jeff Atwood has blogged about this before, and you can find more info here on MSDN.
However…I must say that I agree with Heinzi: it's ugly, annoying, and ultimately quite pointless to repeat legalese in every code file. All you have to do is include it in one file (named e.g. COPYRIGHT or LICENSE) and refer to it in the other files. Makes updating far easier, and prevents noise from cluttering up the code files. More thoughts on this can be found here, very much worth a read: it's both entertaining and true. Don't be a monkey.

Related

How to get Visual Studio quick comments to add a space after the double slash to avoid SA1005?

In Visual Studio, I have a block of code. I highlight it and use Ctrl+k+c to comment out the block. That adds "//" at the start of every line I highlighted. I then try to submit my code... and I run into StyleCop rule "SA1005" that requires all // to be followed by a space or be changed to ////. I would really like to modify Visual Studio so that ctrl+k+c adds "// ". I have not found any extensions or options that make that happen. Does anyone know of a way to do that change (short of writing my own new VS extension)?
My coworker tells me that you can also just hit Ctrl+K+C Ctrl+K+C (that is, apply commenting twice), and it will do ////code. That will pass StyleCop. Do the uncomment shortcut key twice to undo. Apparently, StyleCop doesn't care if there's a space after four slashes, only after two.
It seems some people really like this rule behavior. People will comment out code with a single set of // if they are playing around with stuff but do not want to forget and check it in that way. SA will fail and the code will not go in. Once you really mean to comment out of the code and check it in, then you comment it out again and you are good to go. This, they claim, has saved many from a bad check-in.
You don't need to write your own VS extension, there is already plugin GhostDoc that we are offering - you are welcome to use the free version - and it will generate StyleCop compliant XML Comment templates (which you can tweak too). GhostDoc also generate the comments on triple-slash (///) just like the VS does.

Is there a way to link two comments together in an IDE?

Case: One source file has a comment in it that is directly linked to a comment in another source file (it says see line 315 in xxx.cs for more information). The problem with this approach is that the comment on line 315 may not be at that line number in the future. Is there a way to link comments together in an IDE? (currently using Visual Studio 2010, but use other IDEs from time to time)
You can try this addin (I haven't used this):
http://hyperaddin.codeplex.com/
Besides this addin, the only thing I can think of is using a file link to directly go to the linked file; something like:
// ...
// See file://path_to_file
//...
The link will be converted to an actual link that you can click using Ctrl+Left Click but it won't take you to a given line number - it just opens the file.
The path can be a relative file path or a full file path - full paths work best if all team members use the same folder structure in the project. For example:
// file://w:/projects/GUI/frmMain.cs
Referring to a particular source file and line number is never a good idea, because someone might move things around in the other file without being aware that something is pointing at it. It's better to point at the particular type/method, for example See DoThings() in the MyThing class..
In Java, using Javadoc, you can use #link to do this, for instance See {#link MyThing#doThings()}. Eclipse will automatically update these when using its refactoring tools (e.g. renaming the class or the method). If the change is done manually, Eclipse will still warn that the target of the #link is invalid. (There is also #see which is more appropriate in some situations.)
I'm not sure about C# and Visual Studio, but it's likely that its XML-based doc format offers similar functionality.
The only way to handle this is to put the comment in the same file. Duplicating a comment is not the same as duplicating code, although ideally the code wouldn't need too much explanation in comments.
There are many, many reasons why the comment being in another file will cause pain. As you have stated, the line number may change but also it could be deleted (as they won't know another comment references it), updated in a way that changes its meaning and it is annoying to have to open another file in any case.

Visual Studio ToDo.Who's using?

I'm interesting with statistic and motivation of using task list in VS. Why are you use it or not? Some people i asked even want a tool, that can synchronize VS ToDo with Outlook. What do you think?
IMO you can use Todos for:
Remember that you must do something like "Todo: implement this interface"
To mark a line/block of code as instruction for another coder if your are code in a team like "Todo: you can use foo instead of bar because ..."
If you review your code you can mark any code that he can be improved like "Todo: use Linq instead of foreach"
You can replace the default tasklist-window from visual studio with plugins:
Tasklist replacement for Visual Studio
http://genne-develop.com/
I used TODO for two purposes:
To mark enhancements that can be
done at a later stage. So whenever,
there is slack time, you can pick
one of them out of your pending TODO
list.
Things that are still need to be done while I am coding - so that I can re-visit those places and fix them. This is something like bookmarks except they are visible to other folks even if I forgot to fix them.
I use TODO comment syntax - it's there in code and not in .suo file as mentioned by Benjol.
I use TODO sparingly - only when I have something that I'm not the master of (something another team-member is working on etc.). I treat it as I treat bugs - max 5 at any time.
If I need scaffolding - I create temporary classes with Fake as a prefix in the class-name.
I guess, I don't want my production code to also act as my scrum-board/task-list.
One thing to be wary of about Task Lists in VS is that they are stored in the .suo file, which (I believe) most people tend to exclude from source control.

Is there a 'scratch pad' window in Visual Studio

I currently use notepad to store little notes to myself about my code.
This is usually a mixture of code and requirements.
Is there a 'scratch pad' type window in VS where i could do this.
The other alternative is to use code comment blocks in the source files, but that's not quite what I'm looking for.
Try the sticky notes add in
http://www.davidhayden.com/blog/dave/archive/2008/03/18/VisualStudio2008AddInStickyNotes.aspx
http://code.msdn.microsoft.com/StickyNotes
On "Solution Level" you can add files (text, html or code) to act as notes files.
Also in projects, you can add files, and set the Build Action to None.
Most of the time I'd simply add a .txt file to the solution or abuse comments to do it. However, if you use the scratch pad to store todo lists et cetera you can use TODO: in your comments and visual studio will add them to the built in todo list.
I just found that visual studio has support for git style .md or markdown:
This provides good way of storing notes, requirements and developer instructions such as a readme.
To use: Just add a file to your solution with a .md extension.
I think Stick notes wont support VS 2005. Anyway WinDBG rocks.

How can I define instant AutoCorrect macros in Visual Studio?

By instant AutoCorrect macros, I mean like a list of common typos I do and what to replace them with. For instance, every time I try to type Layer it comes out "LAyer". I'm not using anything by the name of "LAyer", so I'd like it to just automatically replace every instance of LAyer with Layer after I type it.
(As an example of what I mean, go into Word and type something like "Recomend". It will instantly replace it with "Recommend" without prompting by matching it on a list of common mispellings that can be found under AutoCorrect Options.)
I have exactly the same problem (except I commonly mistype a whole bunch of words). Recently I have been typing "chnage" instead of change a lot. (In the code I am working on right now I have classes called ChangedRecord and ChangedDatum and the number of typos I am making is just not funny anymore)
In another thread someone posted a link to AutoHotkey.
I thought I would give it a go and I must say I think it is a great little application (it can do a whole lot more than what we want it to do.
Below is a AutoHotKey script file that should replace the "hotstring" "LAyer" with "Layer" as soon as you type it. I have defined it so that it will only correct if you match case exactly - so it will leave "layer" and "LaYeR" etc.
Also in the script is the hotstring "chnage". This is defined so that it matches the case of the typed word - i.e. "Chnage" becomes "Change" and "ChnagedRecord" becomes "ChangedRecord" (Note that it will change "CHnaGe" to "Change").
An added benefit (most of the time - see comment below) is that these replacements are made in all applications and not just in Visual Studio.
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail#nowhere.com>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
:*:chnage::change
:c1*:LAyer::Layer
Write a Visual Studio plug-in? It's easy to load Office's spell-check and use it in a VS plug-in.
try the free coderush version from developer express. Its macro language should let to recreate this easily. I use the paid version but I would have thought that the free one would still have this functionality
There is an add-in that uses Office spell checking on the Visual Web Developer Team Blog:
http://blogs.msdn.com/webdevtools/archive/2008/11/29/spell-checker-update-2-2-full-support-for-vs-2008-sp1-simpler-setup-and-a-few-bug-fixes.aspx

Resources