如何设置从T4生成的文件的构建操作? [英] How to set Build Action for generated files from a T4?

查看:116
本文介绍了如何设置从T4生成的文件的构建操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是:是否可以在* .tt文件中进行设置,以便将生成的文件设置为指定的Build Action?

The question is: is there a way to have a setting in the *.tt file so that the generated files are set to a specified Build Action?

问题是我正在使用模板生成SQL脚本.我将此脚本用作数据库项目中的预部署脚本.当前,我必须手动将构建操作"设置为每次重新生成文件时都进行预部署-我想使其自动化.

The thing is I am generating SQL script using a template. I use this script as pre-deploy script in Database project. Currently, I have to manually set the Build Action to Pre-Deploy every time a file being re-generated - I would like to automate it.

两个文件-它生成的模板和SQL-都包含在项目中.在Project(* .sqlproj)中,它们是下一个标记:

Both files - template and SQL that it generates - are included into project. In Project (*.sqlproj) they are as next tags:

<PreDeploy Include="Migration\PreDeployScript.sql">
   <DependentUpon>Migration\PreDeployScript.tt</DependentUpon>
</PreDeploy>

<None Include="Migration\PreDeployScript.tt">
   <Generator>TextTemplatingFileGenerator</Generator>
</None>

当我运行定制工具"以重新生成SQL时(我经常需要这样做),然后删除PreDeploy标记,并在其位置放置Build标记.像这样:

When I run Custom Tool to re-generate SQL (I need to do it quite often), then PreDeploy tag is removed and Build tag is put on its place. Like this:

<Build Include="Migration\PreDeployScript.sql">
   <DependentUpon>Migration\PreDeployScript.tt</DependentUpon>
</Build>

它破坏了项目,我需要手动将Build改回PreDeploy.

It breaks the project and I need to manually change back Build to PreDeploy.

可以在Template文件中指定某些内容以始终保留构建操作PreDeploy吗?

Can specify something in Template file to preserve build action PreDeploy all the time?

谢谢!

推荐答案

您可以使用带有通配符的项目组.这将使Visual Studio自动在磁盘上包含与项目相对应的,与通配符模式匹配的任何文件.

You could use an item group with a wild card. This will make Visual Studio automatically include any file on disk relative to the project which matches the wildcard pattern.

仅当磁盘上已存在文件时,这才起作用(即文件仅在加载项目时显示).

This will only work (that is the files will only show when you load your project) if they exist on disk already.

此模式将包括后缀为 g.sql 的所有文件

This pattern will include any files with a g.sql suffix

 <ItemGroup>
    <Build Include="*\*.g.sql" />
 </ItemGroup>

不幸的是,Visual Studio喜欢在保存项目时扩展这些通配符,从而有效地将其删除.解决此问题的最佳方法是使用间接寻址.

Unfortunately Visual Studio likes to expand these wildcards when you save the project, which effectively removes it. The best way to fix this issue is with indirection.

创建一个仅包含项目组的新MSBuild项目文件,然后在SSDT项目中使用<Import>元素导入新项目文件.包含的文件中的内容将合并到您的主要SSDT项目中.

Create a new MSBuild project file with just the item group in it, then import the new project file with the <Import> element in your SSDT project. The content from the included file will be merged into your primary SSDT project.

这篇关于如何设置从T4生成的文件的构建操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆