Visual Studio Post-Build, Pre-Build Macros

http://www.dotnetperls.com/post-pre-build-macros 

You need to use post-build and pre-build macros in Microsoft Visual Studio 2008. You may have two projects that rely on each other but are separate. We can write a macro to copy files from one project to another after the first one is built.

Visual Studio pre-build macro

This page provides an example of using build macros with a DLL in Visual Studio.

Macros in Visual Studio 2008

This approach offers one automated solution to making the two projects work together, at least in a primitive manner. We will copy the compiled DLL to the C# solution's directory. We will use the following command on the post-build event in Visual Studio.

copy "{path1}DLLName.dll" "{path2}DLLName.dll"
DLL (Dynamic Link Library)

Syntax notes. The words including the quotes are actual paths, and they are DOS paths, so they use that funny "\" character. This code runs whenever you build the DLL project. However, let's look at a slightly different solution that is probably a bit better. Here is a command in the pre-build event.

copy "{path1}DLLName.dll" "$(ProjectDir)DLLName.dll"

Explanation. Visual Studio 2008 macros are essentially environment variables contained within parentheses, preceded by the $ symbol—much like Perl. The green italics in the examples must be replaced by you. You can add a macro to a build command by clicking on its name and clicking insert. Next are a couple example tokens.

$(ProjectDir) $(TargetFileName)

Summary

We looked at an example post-build event in the Visual Studio integrated development environment. One thing you can use pre-build and post-build events for is copying DLLs to different solutions at build time. This can automate some interactions between different projects. Here we saw a way to use these macros with a DLL after building a project.

Visual Studio Tips 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值