How to associate a default custom action with a custom file type in Visual Studio?

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

In addition, I created a custom target (build action) in the MSBuild project files. However, I cannot find a way to associate this default assembly action with my custom extension.

For example, if you added a .cs file, the default build action will be “compiled”. I would like to do the same for myself. that is, when adding the .dsl file, I would like the build action to be “Generate”, which is my custom target (and therefore the result of the build).

Is there a way without using the item wizard?

+4
file-type visual-studio msbuild
source share
2 answers

I think the following can help you and others who want to do such things.

If your ultimate goal is to generate code / something when something changes in your .dsl file, I suggest you use "CustomTool". This property is for any element of the project. You write code to generate the code, register the generator assembly, and then set the customtool property of the .dsl file to "MyDslToCsGenerator".

To register the Custom tool with VS, you must run the regasm utility, available with the .Net framework for MyDslToCsGenerator.dll


I know that you said that you do not want to use the object template wizard, but if you have access to the user file template, you can set the default action for the assembly (see the 1st link below)

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

You can also do this programmatically using the DTE ( projectItem.Properties.Item("ItemType").Value = "MyOwnBuildActionChoice" ), as described in the second link below

Useful links:

+6
source share

Not sure about Generate, which I think is your "custom build action". But I was able to install any required build action programmatically using the build API in the build task.

So, suppose that a build action was installed in the file that compiles, you can easily change it to whatever you like at runtime (build time). In my case, I set it to "Embedded Resource". This is possible by linking a custom goals file that runs assembly code that you could write.

Let me know if this is unclear, I can explain further if you are interested.

0
source share

All Articles