MSBuild是说我需要一个主方法的库编译

本文关键字:一个 方法 编译 MSBuild | 更新日期: 2023-09-27 18:17:41

我试图使用MSBuild来编译我的ASP。NET mvc应用程序。由于DLL不需要Main方法,并且我已经指定目标是库,为什么编译器会抛出以下异常:

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]

.csproj文件如下:

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

MSBuild是说我需要一个主方法的库编译

Csc应具有libraryTargetType。默认值应该是Library(见下面的MSDN),尽管在这种情况下似乎不是这样。

更改<Csc步骤如下:

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

From MSDN re TargetType:

输出文件的文件格式。这个参数可以有library的值,它创建一个代码库;exe的值,它创建一个控制台应用程序,模块,它创建一个模块,或winexe,它创建一个Windows程序。默认值为library。更多的详细信息,见/target (c#编译器选项)。