Add this to your csproj
file:
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
Above the <ItemGroup>
declaration.
Question
I have manually created a .csproj file to run using the command line tool msbuild, however, when I try run it it wants to build as an exe. How can I make it build exclusively as a dll? Here is the code in the .csproj file below and the command prompt I execute:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="C:\testing\test.cs" />
<Compile Include="C:\testing\test.Designer.cs" />
<EmbeddedResource Include="C:\testing\test.resx" />
</ItemGroup>
<Target Name="Build">
<Csc Sources="@(Compile)"
Resources="@(EmbeddedResource)"
References="@(Reference)"
TargetType="library"
OutputAssembly="C:\testing\test.dll" />
</Target>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
cmd: msbuild "C:\testing\test.csproj"
Solution
Add this to your csproj
file:
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
Above the <ItemGroup>
declaration.
OTHER TIPS
You need to add the following to your project file:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputType>Library</OutputType>
<!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputType>Library</OutputType>
<!-- Other properties go here -->
</PropertyGroup>
You may have more platforms just add Library for whatever condition meets your need.
Or you can simply do:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputType>Library</OutputType>
<!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputType>Library</OutputType>
<!-- Other properties go here -->
</PropertyGroup>
Once you import the Microsoft.CSharp.targets file, you get the Build target all the ecosystem around it.
The following would work. Note the OutputType property.
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
</ItemGroup>
<!-- You don't need to call the Csc target as Build target is already there once you import the Microsoft.CSharp.targets file -->
<!--<Target Name="Build">
<Csc Sources="@(Compile)"
Resources="@(EmbeddedResource)"
References="@(Reference)"
TargetType="library"
OutputAssembly="abc.dll" />
</Target>-->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
I think I found it out... You have to include these two lines in your .csproj file
<Project>
<PropertyGroup>
<!-- Add Output Type -->
<OutputType>Library</OutputType>
</PropertyGroup>
<!-- Add the MSBuildTools Targets as a reference -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
One thing to Note: A single project file can either create a WinExe Types or a Library Type...