1

I have an ASP.NET Core project that builds properly with VS but fails with TeamCity.

It is a project that compiles to a library, but TeamCity tries to build it as an executable, and complains about the lack of 'main':

CSC error CS5001: Program does not contain a static 'Main' method suitable for an entry point

The content of the .csproj file are as follow:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputType>Library</OutputType>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
    <OutputTypeEx>library</OutputTypeEx>
    <StartupObject />
    <AssemblyName>Test</AssemblyName>
    <RootNamespace>Test</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>
</Project>

Visual studio has no problem building the dll file.

To reproduce:

  • Create an ASP.NET Core (.NET Framework) project
  • Change the output type to library
  • Remove the program.cs / startup.cs files
  • Compile with Visual Studio to confirm a library is being built
  • Build with Team City and an error will appear
Thomas
  • 10,933
  • 14
  • 65
  • 136

2 Answers2

0

To avoid that error, Please look into this SO post or this

You should be using the dotnet core plugin or you can easily configure dotnet build command(if dotnet is present in your build servers).

Or you can refer the MusicStore build.cmd file for reference. This basically downloads and installs the dotnet and all the dependencies and then builds the project.

Hope it helps!

Rohith
  • 5,527
  • 3
  • 27
  • 31
  • Regarding the two posts, we don't have a project.json file; this is a classic .csproj file; it is asp.net core but with regular net libraries, it's not the asp.net core with the core libs built from the command line – Thomas Jun 30 '17 at 03:59
  • the dotnet core plugin will not help because it represent a different build path than the one we're using when developing; as far as VS is concerned, this is a regular csproj; on the TC side, I have cleaned the folders, rebuilt from scratch, etc – Thomas Jun 30 '17 at 04:01
0

I found a workaround; in the project file, VS puts this:

<OutputTypeEx>library</OutputTypeEx>

I need to add one line:

<OutputType>Library</OutputType>
<OutputTypeEx>library</OutputTypeEx>

So it looks like the build with TeamCity is not handling the OutputTypeEx propery but it handles the OutputType one.

I still see this as a bug, but at least there is a workaround.

Thomas
  • 10,933
  • 14
  • 65
  • 136