문제

C# 솔루션을 빌드 할 때 .tt 파일은 .cs 파일 출력을 생성하지 않습니다. 그러나 Solution Explorer에서 .tt 파일을 한 번에 하나씩 마우스 오른쪽 버튼으로 클릭하고 "사용자 정의 도구 실행"을 선택하면 .CS가 생성되므로 빌드 도구 설정이 정확합니다. 맞춤형 도구가 .tt 파일에서 실행되도록 전체 솔루션 빌드를 얻으려면 어떻게해야합니까?

도움이 되었습니까?

해결책

Paul, 빌드 타임에 코드를 생성 할 수도 있습니다. TextTransform.exe 또는 Elton Stoneman의 MSBuild 작업. 다음과 같은 내장 지시문의 행동을 명심하십시오. 집회 그리고 포함 T4가 Visual Studio와 명령 줄 호스트에서 실행될 때 다릅니다.

다른 팁

내 자신의 질문에 대답하면, 그들은이 토론에 따라 설계 시간에 생성되어야합니다.

https://web.archive.org/web/20081227142303/http://www.olegsych.com/2008/02/t4-template-dibirection/

Visual Studio 2013에서는 .tt 파일을 가져와 .CSPROJ 파일 에이 줄을 추가하여 대상을 재생할 수있었습니다.

<PropertyGroup>
  <!-- Get the Visual Studio version – defaults to 10: -->
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <!-- Keep the next element all on one line: -->
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<!-- To enable build tasks on your development computer, install Modeling SDK for Visual Studio. https://www.microsoft.com/en-us/download/details.aspx?id=40754 -->
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<!-- Run the Transform task at the start of every build -->
<PropertyGroup>
  <TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<!-- Overwrite files that are read-only, for example because they are not checked out -->
<PropertyGroup>
  <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
</PropertyGroup>
<!-- Transform every template every time -->
<PropertyGroup>
  <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>

그러나 이것이 작동하려면 Visual Studio 용 SDK 모델링. 이 페이지 에서이 모든 옵션에 대한보다 완전한 설명과 함께이 정보를 찾았습니다. 빌드 프로세스에서 코드 생성.

Visual Studio 2017 (아마도 다음 버전)에서는 사전 건축 이벤트에 추가해야합니다.

"$(DevEnvDir)TextTransform.exe" -out "$(ProjectDir)YourTemplate.cs" "$(ProjectDir)YourTemplate.tt"

추신 : 나를 위해 일한 유일한 해결책.

PSS는 루트 프로젝트 디렉토리에 있지 않은 경우 템플릿으로 경로를 변경합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top