Custom built files

One really annoying thing about DevStudio is that it doesn't let you add a new file type with special build settings, and have those settings apply to every file of that type that you add. (Well, there is always the "Hack the Registry!!!" solution...) These are just a couple of macros I slapped together to make that (a little) easier. I designed these originally to add assembly files to your project, using NASM (a cool little freeware assembler [that creates Win32 objs!] available here) but they can be very easily hacked to work with any file type and build command line imaginable. (A little more hacking would be required for a multi-line build command.) The first macro adds a new assembly file, the second one adds an assembly file you've already written. Just change your path to the executable file in the "NASMPath" variable, and the command line in "NASMSwitches". It'll ask you for the filename in both cases; the first one creates a file with that name, the second will just add that file to your project. Unfortunately, no file dialog is available, or else you could just browse to it. Instead, you need to enter the full path to the ASM file. I haven't tested it with only a filename, so I'm not sure what directory DevStudio will use by default. The first macro even increments the filename each time you create a new one, and adds the file to the project's current directory.


Option Explicit
'
' This is the path to nasmw.exe
'
Public Const NASMPath = "C:\nasm\nasmw.exe"
Public Const NASMSwitches = " -f win32 ""$(InputPath)"" -o ""$(ProjDir)\$(IntDir)\" + _
	"$(InputName).obj"""
'
' The total number of ASM files created so far
'
Private ASMFilesCreated
ASMFilesCreated = 1

Sub AddNewAssemblyFile()
'Description: Add a new Assembly File to your project
	Dim TempConfiguration
	Dim TempDocument
	Dim TempFilename
	Dim TempBackSlashPosition
	Dim CurrentProject
	Dim FileSystem

	Set CurrentProject = Application.ActiveProject
	TempFilename = "Asm" + CStr(ASMFilesCreated) + ".asm"

	If CurrentProject.Type <> "Build" Then
		MsgBox "This project is not a build project."

	Else

		ASMFilesCreated = ASMFilesCreated + 1

		TempFilename = InputBox("Enter the filename:", "Add ASM File", _
			TempFilename)

		If TempFileName = "" Then Exit Sub

		TempBackSlashPosition = InStrRev(CurrentProject.FullName, "\")

		TempFilename = Left(CurrentProject.FullName, TempBackSlashPosition) + TempFilename
		
		Application.Documents.Add "Text"
		Application.ActiveDocument.Save(TempFilename)

		CurrentProject.AddFile TempFileName

		For Each TempConfiguration In CurrentProject.Configurations
			TempConfiguration.AddCustomBuildStepToFile TempFilename, NASMPath + _
				NASMSwitches, "$(ProjDir)\$(IntDir)\$(InputName).obj", _
				"Assembling $(InputName).asm..."
		Next

	End If
			
End Sub

Sub AddExistingAssemblyFile()
'Description: Add an existing Assembly File to your project
	Dim TempConfiguration
	Dim TempDocument
	Dim TempFilename
	Dim TempBackSlashPosition
	Dim CurrentProject
	Dim FileSystem

	Set CurrentProject = Application.ActiveProject
	TempFilename = "Asm" + CStr(ASMFilesCreated) + ".asm"

	If CurrentProject.Type <> "Build" Then
		MsgBox "This project is not a build project."

	Else

		ASMFilesCreated = ASMFilesCreated + 1

		TempFilename = InputBox("Enter the filename:", "Add ASM File", TempFilename)

		If TempFileName = "" Then Exit Sub

		CurrentProject.AddFile TempFileName

		For Each TempConfiguration In CurrentProject.Configurations
			TempConfiguration.AddCustomBuildStepToFile TempFilename, NASMPath + _
				NASMSwitches, "Assembling $(InputName).asm..."
		Next

	End If
			
End Sub


Comments

  • All very well, but how would you set the dependencies??

    Posted by Legacy on 03/30/1999 12:00am

    Originally posted by: Ken Duffill

    If you add a file with a custom build step, the Dev_Studio seems incapable of determining the dependencies. Even if the file is a .c or .cpp and the include files are #include .h files. The very act of setting the custom build step seems to divorce the file from its dependencies.

    I can't find a way of setting the dependencies using macros or add-ins. Anyone got any ideas???

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds