Visual Studio Post-Build, Pre-Build Macros

來源:互聯網
上載者:User

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.

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"

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 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.