Visual Studio에서 새 클래스를 만들 때 새 클래스를 어떻게 기본값으로 공개합니까?
C # Visual Studio 프로젝트의 솔루션을 마우스 오른쪽 단추로 클릭하고 추가 ...> 클래스 ...를 선택하면 공용 수정 자없이 클래스가 생성됩니다. Visual Studio (2008)에서 클래스를 공용 클래스로 기본 설정하려면 어떻게해야합니까?
에있는 파일을 수정해야합니다 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
.
Visual Studio 2010 (10.0) 이하 : Class.zip이라는 zip 파일이 있습니다. 압축을 풀고 파일을 편집하여 public
키워드에 넣은 다음 다시 압축 하십시오 (원본을 백업해야 함).
그런 다음 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache
Visual Studio 명령 셸을 열고 다음 명령을 실행하여 VS가 캐시 (에서 디렉터리로 압축이 풀린 zip 파일)를 다시 빌드하는지 확인합니다 .
devenv /installvstemplates
Visual Studio 2012 (11.0) 이상 : 단일 파일을 편집 (압축 해제하거나 다시 압축하지 않음)하는 것만으로 지금 변경하는 것이 훨씬 더 쉽기 때문에 @JochemKempe의 답변을 참조하십시오 .
업데이트 : 편집하기 전에 관리자 권한으로 선호하는 텍스트 편집기를 여는 것을 잊지 마십시오.
VS2012 에서는 Class.csC:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
파일 로 이동하여 편집하는 것만 큼 쉽습니다.
캐시의 압축을 풀거나 다시 작성할 필요가 없습니다. 저에게 물어 보면 매우 긍정적 인 변화입니다.
VS2015 :C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2017 (RC) :C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2017 (프로페셔널) :C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class
VS2019 (엔터프라이즈) :C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
VS2019 (전문가 용) :C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
시대에 뒤쳐진
VS2019 (미리보기) :C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
Visual Studio 2012 용 기본적으로 공용 클래스를 만들려면 :
이 파일을 편집합니다. C : \ Program Files (x86) \ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033 \ Class \ Class.cs
이렇게 보이려면 :
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
public class $safeitemrootname$
{
}
}
더 많은 정보 : http://aaron-hoffman.blogspot.com/2013/05/edit-default-visual-studio-2012-item.html
고유 한 프로젝트 템플릿을 만들거나 기존 템플릿을 수정할 수 있습니다. 이러한 모든 프로젝트 파일은 템플릿 기반이므로 변경하거나 직접 추가 할 수 있습니다.
다음 링크를 확인하십시오.
마크
다음은 C # 기본 클래스 Item Template을 업데이트 할 재진입 PS 스크립틀릿입니다 . 경로는 사용하는 Visual Studio의 버전 / 에디션에 따라 변경됩니다. 또한 나중에 되돌리려는 경우 원본 템플릿을 백업합니다.
$csharpClassTemplates = @("C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs",
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class\Class.cs",
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs")
$csharpClassTemplates | % {
Write-Output("Updating template $_")
Copy-Item $_ -Destination "$_.backup"
(get-content $_).Replace('public ', '').Replace('class ', 'public class ') | Set-Content $_
}
The answer from JochemKempe works fine, but is a little hard, since you need to rewrite protected files in Program Files
.
Only to update the answer. Templates for Community edition are in the folder:
c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ProjectTemplates
Another solution
But there is another possibility to create new templates. Copy the files from the source folder to user template folder.
e.g. for Windows Form application it can be one of these source folders (for Visual Studio 2017 Community):
c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ProjectTemplates\CSharp\Windows Root\Windows\1033\WindowsApplication\
c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplates\CSharp\Windows Root\Windows\1033\WindowsApplication\
c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows Root\Windows\1033\WindowsApplication\
The default user template folder is (for Visual Studio 2017 Community):
C:\Users\<username>\Documents\Visual Studio 2017\Templates\ProjectTemplates\
And the destination folder for new Windows Form Application template would be:
C:\Users\<username>\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\Windows\1033\MyWindowsApplication\
With this you will have two "Windows Form Application" when creating new project. The distinction between these two is only in the default file name. To make a better distinction it is possible to change the displayed name of the template. To change the template name, update the .vstemplate
file.
The original csWindowsApplication.vstemplate
contains line:
<Name Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2318" />
To change the name you need to change the line to something like this:
<Name ID="2318">My Windows Form Application</Name>
The negative part of this solution is, that you have to rename your new template and you add a new template to existing templates (the old 'incorrect' example will remain and you can still unwillingly use it).
But there is also a good part. You do not need to be administrator to add or update the example. (There is no need to rewrite files in Program Files
folder.)
In addition of JochemKempe great answer, here is how to do it for the .NET core templates.
.NET Core
Instead of editing the templates inside the \CSharp\
directory, you need to edit the ones inside \AspNetCore\
.
VS2019 (Enterprise): C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\AspNetCore\Code\1033\Class\Class.cs
VS2019 (Professional): C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ItemTemplates\AspNetCore\Code\1033\Class\Class.cs
'program tip' 카테고리의 다른 글
ngModel. $ modelValue와 ngModel. $ viewValue의 차이점은 무엇입니까? (0) | 2020.08.30 |
---|---|
연결을 일찍 종료하려면 어떻게합니까? (0) | 2020.08.30 |
모듈에 대한 파이썬 명명 규칙 (0) | 2020.08.30 |
두 필드 비교시 MongoDb 쿼리 조건 (0) | 2020.08.30 |
React.js의 setState 대 replaceState (0) | 2020.08.30 |