Is It possible to run stylecop on a single file in VS2010? - visual-studio

I've tried looking for command line options etc. I'm trying to lower the time I have to wait to see if a build fails due to stylecop.
This option does not appear in any context menus or the tools menu: Is it possible to run StyleCop on just 1 file in a project?

The following context menus should contain commands for running StyleCop:
At solution item in Solution Explorer (rescans the entire solution)
At project item in Solution Explorer (rescans a project)
At any single .cs file in Solution Explorer (scans single file)
Inside text editor of any single .cs file (scans single file)
By the way, which StyleCop version do you use?
Have you considered any issues about wrong installation?

Related

How to execute custom file specific command / task in Visual Studio?

I would like to be able to define custom commands/task/macro for a VisualStudio solution. Then I would like to execute that command for a file that is selected in the Solution Explorer.
There are several possibilities to execute the command that would be fine for me:
a) Right click on the file in the Solution Explorer and choose the command from the context menu (my favorite)
b) Select a file in the Solution Explorer. Then click on a button on a tool bar. The command would then somehow retrieve the selected file from the Solution Explorer.
c) Select a file in the Solution Explorer. Then start a task from the Task Runner Explorer. The executed task would somehow retrive the selected file from the 'Solution Explorer'
I tried to use the VisualStudio extension VsCommandBuddy. However, it does not support file specific commands, see
https://github.com/PaulHuizer/VsCommandBuddy/issues/21
I also tried to use a Grunt or Gulp task that can be started from the Task Runner Explorer. However, I don't know how I can pass/access the file that is currently selected in the Solution Explorer.
https://blogs.msdn.microsoft.com/webdev/2016/01/06/task-runners-in-visual-studio-2015/
=> Is there a VisualStudio extension that easily allows to define custom commands for files?
=> How can I pass/access the file that is selected in the SolutionExplorer in script files (e.g. Gulp, Grunt, Webpack)?
=> Any other comfortable work flow that you would recommend?
It would be possible to write my own VisualStudio extension. But I guess that someone else already knows a solution for this.
1. Create an external tool command:
Tools=>External Tools=>Add
Use cmd.exe as Command
Use /c as first entry for `Arguments' and then specify the command line command you want to execute, e.g. grunt
Use the available variables, e.g. $(SolutionDir), $(ItemPath) (=file path), ... to customize your external command
2. Add external command as entry to the context menu of the solution explorer
Tools=>Customize=>Commands
Select Context menu: Project and Solution Context Menu | Item
Add Command...=>Tools=>External Command 1
Run command
Use the new context menu entry for items in the solution explorer
Stop command
In order to cancel/stop an external command, you can also use the context menu of the solution explorer. If the original name of the command is "Test with Karma", the title will be modified to "(Stop) Test with Karma" as long as the command is running. =>Select that entry to stop the command.
Export settings
Unfortunately those settings can not be stored with the Solution (?). It is however possible to export those settings. Then a colleague can import them:
Tools=> Import and export Settings...=>Next
General Settings=> External Tools List and
General Settings=> Menu and Command Bar Customizations
You can use my Visual Commander extension to define a custom command/macro. On how to get the currently selected file in Solution Explorer see In a VS 2015 extension, how can I get the selected object in the Solution Explorer?

Visual studio extension to redirect output files to specified folder

Usually, visual studio puts output files to bin/debug or bin/release.
When solution contains a large number of projects its not easy to modify each project output manually.
Also edits in csproj files no desirable, because some of them is shared between solutions..
My questions: Is anybody knows a tool, which can quickly configure output path ?
UPDATE: my problem solved by TFS Build
Presumably you have at least one project in each solution that is unique to that solution. In the Post-Build event of that, copy the contents of each project's output to the required location.
We often to this using a batch file. It's crude but effective. In our project that's unique to the solution we create a Release.bat file. This contains a number of file copies to copy all of the required components from the various output directories of the other projects. You can then just run the batch file in the post build event. We usually copy everything to a "Latest Release" fodler when the solution is built. If this becomes a proper release we will rename the Latest Release folder to the actual release number.
If you have multiple build configurations, or even just use the Debug and Release configurations, you can use an If statement in the Post-Build event to decide which batch file to run. So you could create a Debug.bat, Release.bat etc which do what you need. It can be tedious to set them up and get them working correctly at first, but they are very useful once fully implemented.
Customize your project using the msbuild properties which you can do if you follow these steps:
Go to the solution explorer and unload one project by right clicking on it and select Unload Project.
Then right click again on the unloaded project and select Edit Project. This will open the XML definition of your project, and you will have intellisense for the layout which will help you perform the next steps.
In the visual studio editor find the first PropertyGroup tag and add these lines near or at the end of the closing PropertyGroup tag:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<BuildDirectory Condition="$(BuildDirectory) =='' or $(BuildDirectory) == '*Undefined*'">$(SolutionDir)\build\</BuildDirectory>
The above SolutionDir is defined in msbuild properties which you can obtain using this answer: msbuild script using solution information and also check out the well known msbuild properties here
The next step is to find the OutputPath tag for each configuration and edit it like this:
<OutputPath>$(BuildDirectory)\x86\AutomatedDebug\</OutputPath>
The example above assumes you have a configuration named AutomatedDebug with destination platform x86.
The output will be
x:\projects\whereever-your-solution-is\build\x86\AutomatedDebug\
Repeat for each project.
To unload more than one project, collapse all projects in the solution explorer and shift click or ctrl click to select all or some projects, then right click on the selected group to unload, unfortunately you cannot do this for editing, at least in visual studio 2010.
I am the first to admit that this is somewhat cumbersome to do for existing projects, but you could easily create a visual studio project template that has these settings changed so that new projects will use a more convenient default output directory.
You cannot edit the output directory directly in visual studio because the project properties editor escapes any $() enclosed text.
Also you could only modify the OutputPath using the name of a system environment variable enclosed in $(). This last option is to enable a global output directory.
If you build any single project modified in this way using msbuild directly in the commandline the output directory will be created one directory above from where you ran msbuild
..\build\x86\AutomatedDebug
If you are in a team, you should warn them not to edit the output directory directly by hand, as this action will overwrite any customization.
Hope this info is useful.
Greetings.

VS2008: Disable asking whether to reload files changed outside the IDE

I have a Visual Studio 2008 project where some code files are generated with each build (a parser, integrated via MSBuild aka editing the *.csproj file).
VS does not know about the generated nature of these files (i.e. they are not the result of a "Custom Tool). So they "change" with every build, naturally. And VS2008 asks me after every build if I would like to reload those files:
This file has been modified outside the source
Do you want to reload it?
That would be ok if I had one of those files opened and in front of me, but I get these modal dialogs even with none of the code files opened.
So my question is: Is there a way to disable this dialog, per project, per solution or globally?
Thanks!
For VS2008: Tools > Options > Documents > Detect when a file is changed outside the environment
For VS2010/2012/2013/2015: Tools > Options > Environment > Documents > Detect when a file is changed outside the environment
In Visual Studio Pro 2012
There is an "Auto-Load changes, if saved" that works.
Tools > Options > Environment > Documents > Detect when a file is changed > Auto-Load changes, if saved
Because a picture paints a thousand words...
I generate source files on every build, and I don't (normally) get a "file has been modified" message if the file is not open in the editor.
I was getting it just now, however, on a closed file. (That's why I went searching for this question.)
I think that's a bug. The file seems to get wedged sometimes. (But this is the first time it has happened in about a year.)
I think I've found a work-around just now: Open the offending file and then close it again.
The point is, you shouldn't need to turn off changed file detection.
This is an old post, but what worked for me was slightly different and I wanted to share:
This file has been modified outside the source
Go to Tools -> Options -> Debugging -> General and uncheck "Require source files to exactly match the original version". This allows you to use source code which is not the same as original version.

How to make the Visual Studio compiler ignore a file?

Is anyone aware of a way to make visual studio completely ignore a file when compiling? I have a C# solution that has a foo.config file that isn't really a standard config file - it's just a text file. During compiling VS grabs a hold of the file and bombs.
I'd like for it to act as though it's just a text file. I do not have the option of changing the name of the file.
EDIT: Please note that BuildAction does not exclude files from the compiler checking them. It simply decides if the file is compiled into the assembly, whether it's content (like a jpg or something), or whether it is a resource file. For more info: see the MSDN page.
EDIT2: Apparently, if you have a text file that is named foo.config and you have it open while building, VS2005 will pop up an error thinking that the file should be xml. However, if you close the file, VS2005 will ignore it.
Solution: Visual Studio validation causes errors if you have a non-compliant file open during build time. For an example of how to turn this off (for HTML), see Scott Guthrie's post. As Allen mentioned, you should also have the Build Action turned to "None". Unfortunately, this will not stop build errors if you have the file open.
right click > properties
Build Action: set to "None"
Edit: If you're talking about app.config, you really cant mess with the format of that, you need to put it in a different .config file.
I just double checked, VS.net doesnt care as long as its not app.config or web.config and the config file build action is set to "None", it will "error" if you have the file open but it will not cause the build to fail or keep it from building the assemblies.
Close the file and the errors will go away, similar to the errors you get about HTML markup. The displaying of these "errors" is probably a configurable setting in vs.net
The action to take depends on the solution and and file type. For instance (in VS2005), in a C++ solution I can right click on the source file name in the solution explorer and view its properties. The first "General" option is "Excluded From Build", which will allow you to exclude the file from the build process without having it excluded from the project altogether.
I pulled up a .config file in a C# solution, and found a "Build Action" option under the Advanced section. That should probably be set to "None".
Just right click on the file and choose "Exclude from project".
If you still want to see it in your project, select the project and click the "Show all files" button at the top of the solution explorer. This will show all the files in the directory tree even if they aren't actually part of the project.
Are you sure that VS compiling .config file???
You should check it's Build Action in file options and may be set it to none.

How to add a SqlMetal build step in VS2008?

I've created a one-line batch file to run SqlMetal to regenerate a LINQ to SQL DataContext for my database; this works great.
Refresh_DataContext.bat:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sqlmetal.exe"
/server:.\sqlexpress /database:MyDatabaseName
/code:"%~dp0\DataContext.vb" /context:DataContext
/views /functions /sprocs /pluralize
So far I can run this by opening the enclosing folder in Explorer and running the batch file, and I've also added it to the Tools menu (Tools/External Tools.../Add).
Now I'd like to run this batch file whenever I build (in certain configurations). How do I do this?
What you seem to be looking for can be found under "Pre-build event command line" under your project's properties. Click the "Build Events" tab, and you'll have a little space to enter in a command line which does what you want.
Doh! Of course. Web Application projects have pre- and post- build events; Web Site projects don't.

Resources