1

I want my Visual Studio to generate libraries such:

using System.Collections.Generic;
using System.Linq;

each time I create a new project or solution. Is that possible?

Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
  • 3
    Edit your project templates: https://stackoverflow.com/questions/38294114/how-can-i-cause-visual-studio-to-automatically-include-a-using-statement-like-us – CodeCaster Oct 12 '22 at 12:55
  • 2
    You don't need to "generate libraries", you want to use "global usings" - which is possible in the newest templates – Hans Kesting Oct 12 '22 at 12:57
  • 2
    "each time i create a new project or solution." actually I am a little confused. because `using System.Collections.Generic;` would be something you would put into a *.cs file when you create a class for example. This is not the level of projects or even solutions. What exactly are you talking about. please describe the steps you want to take and the precise result you expect to find – Mong Zhu Oct 12 '22 at 13:00
  • its like - im tired to write "using system..." every time i create a new solution or a new project. i want to automate this. Im using those libraries in almost each project i create – artem keller Oct 13 '22 at 08:59

1 Answers1

3

If you're using C# 10+ (default with .NET 6+), you can enable ImplicitUsings in your project file. There are a handful of common namespaces (including the two you mention) that are then automatically imported for all your code files. More info here: https://devblogs.microsoft.com/dotnet/welcome-to-csharp-10/#global-and-implicit-usings

Your .csproj file might look like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>
Kyle McClellan
  • 664
  • 7
  • 23