Domanda

I'm trying to use MSBuild to compile my ASP.NET MVC3 applicaiton. Since DLL's don't require a Main method and I have specified that the target is a Library, why is the compiler throwing the following exception:

CSC : error CS5001: Program 'c:\MvcApplication1\web\bin\MvcApplication1.dll' does not contain a static 'Main' method suitable for an entry point[C:\MvcApplication1\web\MvcApplication1.csproj]

Here's the .csproj file:

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <OutputType>Library</OutputType>
        <AssemblyName>MvcApplication1</AssemblyName>
        <OutputPath>bin\</OutputPath>
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="*.cs" />
    </ItemGroup>

    <ItemGroup>
        <Reference Include="..\lib\*.dll" />
    </ItemGroup>

    <Target Name="Build">
        <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
        <Csc References="@(Reference)" Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).dll" />
        <Copy SourceFiles="@(Reference)" DestinationFolder="$(OutputPath)" />
    </Target>

</Project>
È stato utile?

Soluzione

Csc should have a TargetType of library. The default is supposed to be Library (see MSDN below) although in this case it doesn't seem to be the case.

Change you <Csc step as follows:

<Csc TargetType="library" References="@(Reference)"  ....  />

From MSDN re TargetType:

Specifies the file format of the output file. This parameter can have a value of library, which creates a code library, exe, which creates a console application, module, which creates a module, or winexe, which creates a Windows program. The default value is library. For more information, see /target (C# Compiler Options).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top