VS automatically reference Debug when compiling | Release version dll

Source: Internet
Author: User

Some of the company's early projects put all the projects under a solution, resulting in a slow Compilation of the entire solution, and it is not easy to reuse and maintain class libraries. Therefore, we decided to divide the project into different solutions by function, and then regularly release the dll to the fixed TeamProject on the TFS configuration library. In the future, the project will not be added when the application is referenced, instead, add the dll. But now we have a problem: Release of dll usually releases both Debug and Release versions. Which version should the application reference?

Ideally, the Debug version should be used during development and testing, which facilitates debugging when exceptions are thrown. You can use the Release version when officially deploying it to the production environment, which provides better performance. However, when adding a dll, VS only allows you to select one version.

We know that VS supports saving different compilation options of the project to different configurations. during compilation, the compilation options are determined based on the current configuration. The Debug and Release configurations are created by default. We usually select Debug configuration during development, and Release for Release.

If you can also reference the dll of different paths according to the current configuration when adding the dll, that's fine. Related information is found on stackoverflow, which indicates that the csproj project file can be modified and the dll path can be specified using the VS macro variable. It is quite simple to use NotePad to open and study it. Find the place to reference the Class Library:

<ItemGroup>
<Reference Include = "ClassLibrary1, Version = 1.0.0.0, Culture = neutral, processorArchitecture = MSIL">
<SpecificVersion> False </SpecificVersion>
<HintPath>Lib \ Debug \ ClassLibrary1.dll</HintPath>
</Reference>

You only need to change it:

<ItemGroup>
<Reference Include = "ClassLibrary1, Version = 1.0.0.0, Culture = neutral, processorArchitecture = MSIL">
<SpecificVersion> False </SpecificVersion>
<HintPath>Lib \ $ (Configuration) \ ClassLibrary1.dll</HintPath>
</Reference>

In this way, VS can find the corresponding dll in the Debug or Release folder according to the current configuration.

However, it will be a little troublesome to add the dll in the future. You need to manually edit the csproj file every time. Colleague Wu burst into whimsy,Can I create another folder named "$ (Configuration)" at the time of release, and then directly reference the dll in this folder without modifying the csproj file?. My first reaction was that VS would escape such a path because it was in conflict with the built-in variable name. But in the spirit of "uncertain things need to be verified through experiments", I did this experiment and found that it was okay! VS no matter what string your path contains.

The final conclusion is that the dll must be released to the following three folders at the same time:

  • $ (Configuration) \ MyLibrary. dll
  • Debug \ MyLibrary. dll
  • Release \ MyLibrary. dll

Among them, the dll in the $ (Configuration) Folder does not matter which version. This is just to cheat Visual Studio and will not be used during compilation. When adding dll references, you can directly reference $ (Configuration) \ MyLibrary. dll.

I hope this article will help you.

= Kevin Yang =

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.