3

I really like new productivity tool Sync namespaces in Visual Studio 2022 but sometimes there are rare cases when I need to exclude some file or folder when I synchronize namespaces.

Example 1

By convention, DI extensions should be created in the Microsoft.Extensions.DependencyInjection namespace. From the ASP.NET Core Guide :

We recommended that apps follow the naming convention of creating extension methods in the Microsoft.Extensions.DependencyInjection namespace. Creating extension methods in the Microsoft.Extensions.DependencyInjection namespace:

  • Encapsulates groups of service registrations.
  • Provides convenient IntelliSense access to the service.

Example 2

I have .NET Standard 2.0 project where I want to use constructor-based record declaration and according to this solution Testing C# 9.0 in VS2019 - CS0518 IsExternalInit is not defined or imported ... How do I define/import it? I'm adding the following file to my project:

namespace System.Runtime.CompilerServices;

internal static class IsExternalInit { }

Obviously after doing 'Sync namespaces' this file will be changed and the trick will not work.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Yuriy Gavrishov
  • 4,341
  • 2
  • 17
  • 29

2 Answers2

0

Found this issue since I have the same problem with Extensions.DependencyInjection.

I would like to mention something that may help you with the external init in that case: There is a nuget package for that internal init: https://www.nuget.org/packages/IsExternalInit.

Hope that at least helps you with that problem.

garcipat
  • 376
  • 2
  • 9
-2

You said .NET Standard 2.0 project but not confirmed that its CORE or Framework?

VS2022 and its successor will support mainly CORE version preferably. I don't know why but trying to be universal is the primary goal of Microsoft.

Instead creating parallel world they modifying its own.

Try to install / Add framework minimum 4.8.xx else go back to old visual studio IDE.

  • This should be a comment at best. It doesn't answer the question and contains multiple errors and misunderstandings, starting with the very first sentence. NET Standard 2.0 is .NET Standard 2.0, neither Core nor Framework. A .NET Standard 2.0 library can be used as-is by both .NET Core and Framework projects. As for `I don't know why` it would not be very clever to have different IDE versions to support different runtimes. When the IDE is supposed to work with different *languages*. Had MS done what you proposed, developers would storm Redmond and burn the VS team building to the ground – Panagiotis Kanavos Aug 29 '22 at 06:07
  • And the final sentence is completely wrong. .NET Framework 4.8 is still .NET Framework 4.x and still compatible with .NET Standard 2.0. Installing it would have absolutely no difference. In fact, it's probably already installed. `Go back to old VS` is no solution in most cases. In this case it would have no effect. If you don't like a refactoring, you turn it off. You don't nuke your development environment – Panagiotis Kanavos Aug 29 '22 at 06:09