Visual Studio .NET 2005’s Command Line Tool.

What I’m trying to do: call the link.exe to make a SampleFile.res into a SampleFile.dll.

Approach 1: Manual call from the Command Line Tool (CLT).
I don’t like this idea because I’d have to open the CLT every time I want to recompile the *.res into a *.dll.
[Call 1] C:\Program Files\Microsoft Visual Studio 8\VC\bin> C:\Program Files\Microsoft Visual Studio 8\VC\bin\link.exe -machine:x86 -dll -noentry -out:C:\ProjectFoo\Installer\bin\Debug\SampleFile.dll C:\ProjectFoo\Installer\bin\Debug\SampleFile.res

[Call 2] C:\Program Files\Microsoft Visual Studio 8\VC\bin> link.exe -machine:x86 -dll -noentry -out:C:\ProjectFoo\Installer\bin\Debug\SampleFile.dll C:\ProjectFoo\Installer\bin\Debug\SampleFile.res

***I showed two calls for a reason. They do the same exact thing and both work successfully on the CLT.

Approach 2: Automate call from the Pre-Build event in the project.
I like this approach because it allows me to edit the file whenever I want and then compiles the *.res to a *.dll as needed. I put the following in the Pre-Build event section for my project.
C:\Program Files\Microsoft Visual Studio 8\VC\bin\link.exe -machine:x86 -dll -noentry -out:C:\ProjectFoo\Installer\bin\Debug\SampleFile.dll C:\ProjectFoo\Installer\bin\Debug\SampleFile.res

KABOOM! Error 1 The command “…” exited with code 128.

SOLUTION? COPY AND PASTE!
So looking at the properties for the CLT, here’s what is called when I click it:
%comspec% /k “”C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat”” x86

OO…a batch file, let’s take a look at it. Since I’m on an x86:
call “%~dp0bin\vcvars32.bat”
(C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat)

More batch files? Keep them coming!
“%VS80COMNTOOLS%vsvars32.bat”
(C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat)

FOUND IT! Well, it’s the end of the road here, so I copied the entire batch file contents and pasted it before the call in the Pre-Build event. Worked like a charm…now I need help with finding out what is the right approach to doing this using best practices. Meanwhile, I’m going to hack this section up and minimize the calls and settings to let it keep working.

(10:54:43 AM) kashifkhan17: yup env settings it was
Thanks, Kashif! For helping me think through it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve this: Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.