inquisitive
inquisitive

Reputation: 1680

Generating both dll and exe in MSVC

For a visual C# project in microsoft visual studio IDE, what is the configuration settings to be used, so that it could generate both exe and dll outputs?

Upvotes: 1

Views: 3085

Answers (3)

adrianm
adrianm

Reputation: 14726

I know this is an old question but it is possible to do a lot of things in the proj-files that is not possible in the user interface.

For this specific issue you just do like this:

  • Create a new project configuration, e.g. ReleaseExe
  • In the project's csprojfile you will find the following line

    <OutputType>Library</OutputType>
    
  • After that line add the following line

    <OutputType Condition="'$(Configuration)|$(Platform)' == 'ReleaseExe|AnyCPU'">Exe</OutputType>
    

Save, open the project and use batch build to build both the dll and exe

The nice thing is that you can use the Condition attibute on all tags in the project file. I have a project where I need to create two versions based on different 3rd party assemblies. To solve that I just add a condition to the reference tag.

<Reference Include="3rdParty" Condition="'$(Configuration)|$(Platform)' == 'Release1|AnyCPU'">
    <HintPath>Release1\3rdParty.dll</HintPath>
</Reference>
<Reference Include="3rdParty" Condition="'$(Configuration)|$(Platform)' == 'Release2|AnyCPU'">
    <HintPath>Release2\3rdParty.dll</HintPath>
</Reference>

Upvotes: 0

VJAI
VJAI

Reputation: 32758

What you want can be easily achieved using nant. You have to create a simple xml file that is the script and that can be easily executed through a batch file. Once you created them then it's very easy no more manual work, every time when you need to build the project all you have to do is just execute the script.

Here is an excellent tutorial about nant.

Upvotes: 2

As Darin points out in comments, there is no setting to do this. However, you can achieve it via build events and batch scripts

  1. Create a pre-build event on the dll project to call a batch script
  2. In the batch, copy the csproj for the dll project
    • Modify the XML content of the copied csproj to change the output type to exe
    • Modify the output directory of the copied csproj
  3. Run this in Visual Studio

You will now get a copy of your csproj generated which outputs to exe. You can add the second csproj into visual studio and every time you build, it should synchronize the exe csproj and build it.

Some tips:

  • You can modify csproj's using Powershell. See here
  • You may want to modify all cs files in the copied csproj to be links

Upvotes: 0

Related Questions