It is a well known issue with Resharper that it fails to recognize generated C# files using Custom Tasks (making intellisense fail). Does anyone know how to fix this without adding the files to the project?
(BTW, including the generated files in the project or creating a separate assembly and other such flawed suggestions are totally out of the question).
Can we write a Resharper plugin for this? We have a fairly large number of developers that cannot use Resharper, so this would well be worth the effort.
Can we somehow add the obj/*.g.cs files to
Resharpers non msbuild based csproj parser (lurking somewhere within Resharper)?
Is the method used by Resharper on how to resolve the list of .cs files to include documented somewhere?
As this issue is experienced and reported again and again for years, surely there must be someone who has cracked it by now?
I found an extension for Resharper: ReSharper.ExternalCode.
Tip for Antlr: add obj\Debug in Resharper -> Code Inspection -> External Code and reload solution.
It's works for me.
Related
Visual Studio has a "Refactor Rename" feature where I can right-click any type or member and rename it, and it will update all references within a project or solution to match. Is this functionality accessible from MSBuild command line tools, without having to open Visual Studio?
(I'm doing this because I have a project that is so large that Visual Studio runs out of memory while attempting to calculate where the rename is needed).
As far as I'm aware that's not something that's available outside of Visual Studio; although you probably have a couple of avenues available for getting it done.
The first thing that I'd try is using a lighter editor, VSCode, Atom, etc. Something that uses less memory, but will still hopefully let you get the rename done. You might have to use a regex find/replace to get it done; whether that's an option kind of comes down to if you can make an accurate regex.
If you can actually get the project open in VS with no (or less, at least) problems, then you could also start unloading projects that aren't relevant to the rename. If you know that it's only available in certain projects then unload everything else, perform your rename, and reload the projects. If it's everywhere then you might still be able to do something similar to this, perform the rename in a few projects, unload them, load the next few, rename, etc. Although I'm honestly not 100% sure that'll work, I've never attempted it.
Regardless of what you try, if you haven't already be sure to have your code in source control just in case. I'm sure this is doable, but maybe not via the VS command line.
No. There is no shipping msbuild target, task or tool to rename variables from the command line.
You could of course write yourself. :)
But I highly suggest using Visual Studio Code as an alternative to Visual Studio for loading large numbers of projects. It's an outstanding cross platform IDE. And who knows, perhaps someone wrote a plugin for it to rename variables...??
I have a C# WinForms project, which I am working on in Visual Studio 2017 (although it was originally created in the 2015 version).
I don't recall having done anything special, but it has added a file called .dtbcache, that it wants to add to git. The file has no extension, and a Google search doesn't show any results.
The file is located in ..\repos\myprject\.vs\MyProject\DesignTimeBuild. Which means that the "dtb" part of the file name probably means design time build, but that doesn't really make it that much better.
Can I delete it or add it to .gitignore? I would prefer not to include it in our git repository, unless it is required.
Short answer: You can safely exclude it from your Git repo.
Long answer:
You're right that dtb stands for Design Time Build. This is a file automatically created by VS2017, with a bit more information here and here (links to a blog from someone working on the Visual Studio project system). In summary, it's Visual Studio more or less extrapolating what files will be produced in order to make sure Intellisense is fully available as intended.
From the linked articles, one of the purposes of this is to make sure Visual Studio has an answer in certain cases:
Given an assembly reference in the project file, what assembly on disk is that reference going to actually refer to at compile time?
Given a XAML file, what is the code that is going to be generated by the XAML compiler at compile time going to look like?
Given a glob file pattern (*.cs), what files are actually going to be included at compile time?
So the files, being generated on the fly, are not needed in your Git repo, and can safely be excluded. Moreover, from what I can tell, these files are specifically made and used by Visual Studio 2017.
I am a recently converted VB developer to C#, but there is one thing thus far that I haven't been able to find. In VB when I setup a new project I can specify the namespaces used in the project and add them to the default imports for all classes (so everything automatically has them as if I added "Imports System.Data.OracleClient" to each class). With C# I've found that I'm always typing these in for each new class. Is there a way to setup defaults for projects so it at least appends those to every class file for me automatically?
No there is no way. C# does not support the concept of project level imports or project level namespaces.
The only thing you can do is alter the item template you are using (Class.cs or Code.cs) to have the namespaces you would like. These files are located under the following directory
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\itemtemplatescache\CSharp\Code\1033
Under here you should see a Class.zip and Code.zip directory each with a .cs file under them. This is the template file used when you do an "Add New Item" operation in Visual Studio. You can change these to meet your needs and have the default namespaces you'd like.
A slightly easier solution though is adding a per-user code file for the particular project you'd like. Simply create a code file you want to be the template for your application and then place it in the following directory.
C:\Users\YourUserName\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#
This file will now show up whenever you do a "Add New Item" operation.
Others have suggested using templates etc. Personally I find it's just not a problem - I type the name of the class that I want to use into Visual Studio, and even if it's not found the "smart tag" (or whatever it's called) icon pops up. I hit Ctrl-. and it adds a using directive for me.
I think ReSharper helps to make this work even better, but it's so automatic for me now that I don't really think about it much any more. (I suspect the difference is that with ReSharper I can hit Alt-Enter at any point in the line and it'll offer the correction, instead of having to have the cursor in the type name itself for Visual Studio.)
With C# 10 this answer has changed.
C# 10 introduces [Global using directives][1]:
Global using directives
You can add the global modifier to any using directive to instruct the compiler that the directive applies to all source files in the compilation. This is typically all source files in a project.
no, there's no my namespaces in C#. I think you can probably accomplish the same thing with project templates or code snippets.
See this post for the answer..
Which, in a nutshell, is adding the usings you want to a template.
I believe you want to start here.
I have a .exe app which I want to understand better - I can see it in reflector
Is there any way to get reflector to create a VS project with the code so I can view it properly in Visual Studio?
Nothing special is needed, it is built into Reflector, albeit not very discoverable. Right-click the assembly in the left pane and choose Export. You'll get a chance to change the output directory. Click OK and Reflector starts decompiling the code, creating a source file for each individual class. And creates a .csproj file which you can open in Visual Studio.
Check out Jason Bock's FileGenerator, it might be what you are looking for.
I've used Denis Bauer's Reflector.FileDisassembler http://www.denisbauer.com/NETTools/FileDisassembler.aspx. It works well enough to compile and step through the code.
Yea there is, but it doesn't come cheap
http://www.remotesoft.com/salamander/
I have used it to decompile assembly, but I've never used the feature to decompile it into a project so can't give you a review on that. The quality of the decompiler will match the one in reflector.
They also be some legal issues associated with decompiling exe into project - and source for recompilation, so use it with care.
so I'm writing a VS2008 C# Add-In to automate AspectC++ weaving in C++ projects. I'm generating the C++ source files (now woven with aspects), but I can't figure out how to compile them as part of the pre-build step. Is there a convenient way to specify new source within the IDTExtensibility2, EnvDTE90, or VslangProj90 namespaces? I've tried using the VCProject and VCProjectEngine interfaces as well as marking the files for inclusion programmatically via the 'ExcludedFromBuild = false' flag. No luck.
I noticed that the commercial AspectC++ Add-In bypasses cl.exe by putting a wrapper around it and the ac++.exe aspect compiler. So they must call their own cl.exe which then calls ac++.exe before preparing the generated source files for the real compiler. That seems like a hack to me, is there not a better way? I'm really stumped on this one, any help would be appreciated.
Why not just include the generated file into the project that you then build?