When I run tests in Visual Studio I have a test folder containing testdata. To reach these I use
File.ReadAllText(Path.Combine("testData", "input.html"));
But instead of looking in the project folder where the testdata is located
C:\repos\myproject\testdata
Visual studio tries to find the file in
`C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\testData\input.html`
Which results in the following error:
`Message: System.IO.DirectoryNotFoundException : Could not find a part of the
path 'C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\testData\input.html'.`
Since we are several people working with the same project we need to use relative paths. Where can I change the relative path that VS is using? I'm using Visual Studio Professional 2017.
I have tried the first solution in
How to define relative paths in Visual Studio Project?
but both the solution and project property page is different in VS Pro 2017.
Images:
Solution properties
Project properties
Related
Whether user can customize the below vswhere.exe path while visual studio installation?
C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
Reason for asking this query is ,I used vswhere exe for find the VS2017 & 19 installation path in my project.
"VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
Suggest any other way to find the Vswhere exe path.
From Microsoft ( https://github.com/Microsoft/vswhere/wiki/Installing ) :
Starting with Visual Studio 15.2 (26418.1 Preview) vswhere.exe is installed in
%ProgramFiles(x86)%\Microsoft Visual Studio\Installer.
(use %ProgramFiles% in a 32-bit program prior to Windows 10).
This is a fixed location that will be maintained.
This means that vswhere will be located at %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe no matter what options the user chose on the Visual Studio installer or MSBuild Tools installer.
Note that if you install vswhere using Chocolatey (instead of the VS/MSBuild installer), it will be located at %ProgramData%\chocolatey\lib\vswhere\tools\vswhere.exe
I have a Visual Studio 2013 extension that has a reference to Microsoft.VisualStudio.TeamFoundation.VersionControl.dll, from which the following type can be obtained:
Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlEx
Today I uninstalled all previous installations of Visual Studio and then installed Visual Studio 2017 Enterprise with the options ".NET desktop development" and "Visual Studio extension development".
I opened the project with Visual Studio 2017 and had to replace some of the references (EnvDTE, envdte80, Microsoft.VisualStudio.Shell.15, etc) and also installed the nuget package Microsoft.TeamFoundation.VersionControl.All.
Unfortunately the namespace Microsoft.VisualStudio.TeamFoundation and therefore VersionControlEx are not recognized.
I have searched the file on my machine with FileLocator Lite and it does not exist.
Any idea how has this changed in Visual Studio 2017?
I basically to access the PendingChanges window.
Thanks in advance.
By doing a search, I was able to find the file in there:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
I also found copies associated with other versions of Visual Studio. Given the path of the file, it appears to be included along with Team Explorer.
I suspect the reason you were not able to find the file on your machine is that you had uninstalled your prior versions of Visual Studio and Visual Studio 2017 did not release with Team Explorer.
If you update your version of Visual Studio or you run the standalone installer, I expect that you will be able to find the file.
How do I open I a Visual Studio Code folder in Visual Studio 2015?
If I open it as a "Web Site", it tries to treat the node_modules directory as part of the project's normal JavaScript files and hits an error when the path exceed the maximum path length.
But I can't open it as any other project type unless I first create a project of that type and then move all the VS Code files into that folder.
Should I be trying to open it as a web site?
Or should I create a new project and then copy the files + folders into it?
Is there any advantage to having it as a project?
If I do create a project, it makes it difficult to work together with someone who is just using VS Code?
And if I use a project, which project type should I select?
Finally folder view has arrived in VS 2017 :)
You can find more details in here.
Currently there is no way to open a folder directly with Visual Studio.
Why? Because Visual Studio and Visual Studio Code only shared their name, not the idea behind it. To extend Jenny O'Reilly answer:
Visual Studio Code is a folder oriented editor
This means VSC has the same Point-of-View to your Project as the File Explorer.
Visual Studio (not Code) is a solution oriented integrated development environment (short IDE)
Instead every Project in Visual Studio needs a *.sln Solution-File as Root Component. From this point Visual Studio looks at your Project. An example would, if you copy File in your Project Folder, they wouldn't be recognized from Visual Studio. You have to add them first to your sln File, to see them. It also allows the developer to combine multiple projects (*.csproj,..) into one single Solution to build.
This means the idea behind these two editors is completely different.
Visual Studio (not code) Project-types for Web
There are Node.js Tools for Visual Studio
This will provide Node.js built-in project templates
Visual Studio 2015 comes with TypeScript templates
Workaround 1
A workaround would be a Blank Solution in which you set up your Visual Studio Code Project.
Workaround 2
Another trick would be the answer to this question. You can open your Project Folder as a Website Project.
File -> Open Website -> File System and choose the folder
Update
As you mentioned, there will be errors because Visual Studio tries to build the solutions. For the next few readers of this response, the work around for this (as John Pankowicz writes in the comment) is:
Right-click Web Site in Solution Explorer -> Property Pages -> Build -> Uncheck "Build Web Site as part of solution"
Update 2
(Thanks to JC1001 for this update)
The next version of Visual Studio (Visual Studio "15") will support opening a folder. This is mentioned in the Visual Studio Blog.
Also like in Visual Studio Code, there will be a prompt command for opening Folders. Right now you can use this in the preview version:
devenv /command “file.openfolder FOLDER_PATH”
In the future you will be able to use:
devenv FOLDER_PATH
Opinion
Personally I wouldn't recommend Visual Studio (not code) for HTML/Website projects without server-side-development, because I don't see any features. Even the intellisense suggests to me sometimes bad HTML Code (it's not the IDE's fault).
After all web projects are still text files. You can easily control group projects like this with Version Control. Visual Studio Code even provides an integrated Git support.
Visual Studio Code does not create "project files" that you can open in Visual Studio 2015. Basically, when you open up a Node website in Visual Studio, you need to re-create the folder structure in VS2015 and create a "project file".
I haven't seen any better ways of doing this, but will be happy when we can open a folder just as easilly as we can with VSCode
I'm sure it's not the best way but..
Open an existing .sln with notepad, change the names, save as [name of your project].sln.
Open with Visual Studio.
I find myself removing the following import statements in nearly every C# file I create in Visual Studio:
using System.Collections.Generic;
using System.Linq;
using System.Text;
Of course its really easy to do this with Resharper, but I really should not have to.
There must be a few template (class, interface) somewhere in the VS directory, from which I can remove the offending lines. Where do I find these files? Is there a better way to control the default import list?
2022
Visual Studio 2022 is now a 64bit process so its location has changed to using Program Files instead.
%ProgramFiles%\Microsoft Visual Studio\<year>\<edition>\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.cs
Year
Edition
Absolute path
2022
Community
%ProgramFiles%\Microsoft Visual Studio\2022\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Enterprise
%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Professional
%ProgramFiles%\Microsoft Visual Studio\2022\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Preview
%ProgramFiles%\Microsoft Visual Studio\2022\Preview\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
2017 through 2019
Visual Studio 2017 changed the directory location to use release year instead of its internal version number, and is additionally dependent on your edition (Professional/Enterprise/etc.):
%ProgramFiles(x86)%\Microsoft Visual Studio <year>\<edition>\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.cs
Year
Edition
Absolute path
2019
Community
%ProgramFiles(x86)%\Microsoft Visual Studio 2019\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Enterprise
%ProgramFiles(x86)%\Microsoft Visual Studio 2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Professional
%ProgramFiles(x86)%\Microsoft Visual Studio 2019\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
2017
Community
%ProgramFiles(x86)%\Microsoft Visual Studio 2017\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Enterprise
%ProgramFiles(x86)%\Microsoft Visual Studio 2017\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Professional
%ProgramFiles(x86)%\Microsoft Visual Studio 2017\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
2012 through 2015
Starting with VS 2012, the templates are not zipped, so you can edit each .cs template in each applicable folder directly.
%ProgramFiles(x86)%\Microsoft Visual Studio <version>\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.cs
Year
Version
Absolute path
2015
14.0
%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.cs
2013
12.0
%ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.cs
2012
11.0
%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\1033\Class.cs
2010 and older
Extract, edit and recompress the ZIP file. Paths are for the class template, but interface templates are in the same folder.
You may want to edit the VS template file in each to remove the fact that they don't automatically add references to the assemblies System, System.Data and/or System.Xml.
%ProgramFiles(x86)%\Microsoft Visual Studio <version>\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
Year
Version
Absolute path
2010
10.0
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
2008
9.0
%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
2005
8
%ProgramFiles(x86)%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip
Notes
Express Editions
In Express Editions you will have to search in the subdirectory WDExpress inside the IDE folder, so e.g. for VS 2015 Express:
%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\WDExpress\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Other Languages
If you don't use the English version of Visual Studio, the folder 1033 may not exist, but a different number representing your language. For example it is 1031 in a German installation.
You're looking for the following directory:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp
Each template is a ZIP file inside the 1033 (English) subfolder of one of the categories in this folder. You can edit the .cs file inside the ZIP file.
If you're on a 32bit system, remove the (x86). VS2005 is Microsoft Visual Studio 8, and VS2010 is Microsoft Visual Studio 10.0.
Note that these templates are not per-user. You can make per-user templates by copying those ZIP files to My Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#.
For Visual Studio 2012, to remove these from the default class.cs file, the item template could look like this (do not include/remove using statements):
Default Class Template file:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
using System;
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
More info here: http://aaron-hoffman.blogspot.com/2013/05/edit-default-visual-studio-2012-item.html
New class templates might be located in different folders depending on the project type as well. While working in a Web Project in VS 2015, I found that when editing the file
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
I was unable to see any difference in the default template when creating a new class. It was only after editing the file
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\WebClass\Class.cs
that I was able to create a new class with the default format that I wanted.
New addition to the excellent info from Sam Harwell. I'm using Visual Studio 2019 Community, and the path to my class template is the same as already mentioned, except for "Enterprise", which is replaced by "Community". So:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
It's also worth mentioning that the Class "zip" folder isn't a zip at all on my installation. It's simply another folder.
Another "gotcha" is that if you are running a Preview edition, it's in it's own "Preview" folder:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
For other templates, the folder to look for is:
C:\Program Files (x86)\Microsoft Visual Studio\[YEAR]\[EDITION]\Common7\IDE\ItemTemplates
So, on my machine it is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\ItemTemplates
[Edit 10 May 2020]
You also need to check the value of "User item templates location" in Tools | Options | Project and Solutions / Locations
I hope this helps someone.
None of the mentioned solutions worked for me so I'm posting the way how I have solve it for VS 2019 (16.7.7):
I have followed the steps from here:
I have opened the dir with the template:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
Edited the template adjusting it to my needs and saved (Class.cs)
Zipped both files: Class.cs and Class.vstemplate
Moved the zip to: cd "%USERPROFILE%\Documents\Visual Studio 2019\Templates\ItemTemplates"
I'm not sure if it is necessary but I have run devenv /installvstemplates
Same as above (not sure it is needed) restarted VS
Old question - new answer:
Sorry for the, maybe, offending question: Why would you care about it at all.
Productivity Power Tools (visual studio extension, i would recommend using it anyway) -> enable the option / setting called: "Remove and Sort Usings on save"
No extra click / keyboard shortcuts / manual template modification etc ... since you have to save your files anyways.
Just want to add to the excellent answer from Sam Harwell. There might be more than one class template, for instance AspNetCore has its own template at:
C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\Common7\IDE\ItemTemplates\AspNetCore\Code\1033\Class\Class.cs
I frequently work with the System.IO namespace. Is there a way to have that be included with each new project I create?
Thanks
Adding it to the default template might be tricky, I would leave it alone.
You can easily create an empty project, make all sorts of settings and modifications and save it a s a new template (File|Export as template). A lot safer in the long run.
Just make it a habit of starting your new projects from your own custom templates.
If you really want to you can edit the contents of the file that is usually at c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Windows\1033\WindowsApplication.zip
Check out Changing the default using directives in Visual Studio.
The basic answer is to modify the class.zip file located here (for various options):
Visual Studio 2008
For 64 bit:
C:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
For 32 bit:
C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip Visual Studio 2010
For 64 bit:
C:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
For 32 bit:
C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
And then run devenv.exe /installvstemplates in one of the following locations:
Visual Studio 2008 64-bit
cd C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\
32-bit
cd C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
Visual Studio 2010
64-bit
cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\
32-bit
cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\
A more complete answer is here and here.