MSBuild tries to create exe instead of dll

I manually created a .csproj file to run using the msbuild command-line tool, however, when I try to run it, it wants to build as exe. How can I create it solely as a dll? Here is the code in the .csproj file below and on the command line that I am executing:

<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"
+4
source share
3 answers

Add this to your csprojfile:

<PropertyGroup>
  <OutputType>Library</OutputType>
</PropertyGroup>

Over the ad <ItemGroup>.

+3
source

You need to add the following to the 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 a library for any condition that meets your requirements.

Or you can just 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>
0
source

Microsoft.CSharp.targets, .

. OutputType.

<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>
0
source

Source: https://habr.com/ru/post/1539451/


All Articles