我该如何关联的自定义默认生成操作在Visual Studio自定义文件类型? [英] How do I associate a custom default build action to a custom file type in Visual Studio?

查看:336
本文介绍了我该如何关联的自定义默认生成操作在Visual Studio自定义文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我建立了一个自定义文件类型的语言服务。

I have a language service that I have built for a custom file type.

另外,我已经在我的MSBuild项目文件创建一个自定义的目标(建设行动)。不过,我无法找到任何方式的生成操作默认关联到我的自定义文件扩展名。

In addition, I have created a custom target (build action) within my MSBuild project files. I am however unable to find any way to associate that build action by default to my custom file extension.

例如,如果添加了一个cs文件,生成操作默认为编译。我想为我这样做。 添加.dsl文件,即当我想生成操作是生成,这是我自定义的目标(并因此建立行动)。

For example, if you add a .cs file, the build action defaults to "compile". I would like to do the same for mine. i.e. when adding a .dsl file I would like the build action to be "Generate", which is my custom target (and therefore build action).

有没有使用项目向导的方式?

Is there a way without using a item wizard?

推荐答案

我认为下面可以帮助你和其他人谁是想要做类似的事情。

I think the following might help you and others who are wanting to do similar things.

如果你的最终目标是产生code /某事时,你的.dsl文件有什么变化的话,我建议你可以使用CustomTool。这是任何工程项目的性质。你写code产生code,注册发电机组件,然后将.dsl文件MyDslToCsGenerator的customtool财产。

If your end goal is to generate code/something when anything changes in your .dsl file, then I suggest you could use "CustomTool". It's a property on any Project Item. You write code to generate code, register the Generator assembly, then set the customtool property of the .dsl file to "MyDslToCsGenerator".

为了注册自定义工具在VS,你必须运行regasm实用工具,可与.net对MyDslToCsGenerator.dll框架

In order to register the Custom tool in VS you have to run "regasm" utility, available with .Net framework against the MyDslToCsGenerator.dll


我知道你说你不想使用项目模板向导,但如果你已经进入到自定义文件模板,那么你可以设置默认生成操作(见下面的第一个链接)

I know you said that you don't want to use Item Template wizard, but if you've access to the custom file template, then you could set the default build action (see 1st link below)

<ProjectItem SubType="" TargetFileName="$fileinputname$.dsl" 
ReplaceParameters="true" ItemType="Embedded Resource" 
CustomTool="MyDslToCsGenerator">MyFile.dsl</ProjectItem>



您也可以做到这一点编程方式与DTE( projectItem.Properties.Item(的ItemType)。值=MyOwnBuildActionChoice)作为第二个链接说明如下

You could also do this programmatically with DTE (projectItem.Properties.Item("ItemType").Value = "MyOwnBuildActionChoice") as explained in the 2nd link below

帮助链接:

  1. <一个href="http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/6bfe13fd-618e-477f-ab66-0f24c6b5d4c3">How设置生成操作由一个Visual Studio项目模板创建一个项目?
  2. <一个href="http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/bd74f1bc-2c60-4f9c-b29f-e50bf16aadfc">Using DTE设置自定义生成 行动
  1. How to set the Build Action for an item created by a Visual Studio item template?
  2. Using DTE to set a custom build action

这篇关于我该如何关联的自定义默认生成操作在Visual Studio自定义文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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