Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I associate a custom default build action to a custom file type in Visual Studio?

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

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.

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?

like image 284
Darien Ford Avatar asked Jul 01 '09 04:07

Darien Ford


People also ask

How do you set a build action property in Visual Studio?

To set the build action for a file, open the file's properties in the Properties window by selecting the file in Solution Explorer and pressing Alt+Enter. Or, right-click on the file in Solution Explorer and choose Properties.

How do you change a build action to an embedded resource?

Right-click the XAFML file in the Solution Explorer and select “Properties”. Set the Build Action property to “Embedded resource”.

How do I change the build command in Visual Studio?

Open the project's Property Pages dialog box. For more information, see Set C++ compiler and build properties in Visual Studio. Choose Configuration Properties to enable the Configuration box. In the Configuration box, select the configuration for which you want to specify a custom build tool.

How do I change my build action?

To change the build action assigned to a file, click the file in the build list, and then click Change Build Action to open the Change Build Action dialog box. From the Build Action drop-down list, select the build action that you want to assign to this file.


1 Answers

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

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".

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>

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

Helpful links:

  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
like image 154
Vin Avatar answered Nov 15 '22 10:11

Vin