0

I'm trying to create a C# application (.cs files). Since I'm using Visual Studio Code, I have to use the command line in order to compile the project, but when I launch MSBuild, it generates a .dll file.

MSBuild version : 15.8.169.51996

This is my .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <PropertyGroup>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>

    <PackageReference Include="Microsoft.Net.Compilers" Version="3.1.1">

      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Thanks in advance!

baruchiro
  • 5,088
  • 5
  • 44
  • 66
GabryLinux
  • 155
  • 3
  • 8
  • Possible duplicate of [Build Visual Studio project through the command line](https://stackoverflow.com/questions/5669765/build-visual-studio-project-through-the-command-line) see also **[Walkthrough: Use MSBuild](https://learn.microsoft.com/en-us/visualstudio/msbuild/walkthrough-using-msbuild?view=vs-2019)** from the online Docs – Ňɏssa Pøngjǣrdenlarp Jul 28 '19 at 16:22
  • Thanks but msbuild is still compiling a .dll instead of an .exe. I think the problem is inside the .csproj . Any ideas? – GabryLinux Jul 28 '19 at 19:13
  • You need to specify runtime, so that MSBuild know which executable to include. – user4003407 Jul 28 '19 at 19:17

1 Answers1

4

Deployment in .NET Core

Because of you are using a netcoreapp, officially called .NET Core, things are little different here.

.NET Core is a cross platform framework. It's mean that software you wrote will execute in both Windows, Linux and OSX. Have you seen an .exe running on Linux? Not in the usual way..

After you understand this, you have several options:

  1. Use the .dll as expected. With . NET Core, you run your .dll by the command dotnet your.dll.
  2. You can use the SCD deployment and set the RuntimeIdentifier to be win10-x64.
  3. You can upgrade to .NET Core sdk 2.2 (netcoreapp2.2) and use the FDE deployment.
baruchiro
  • 5,088
  • 5
  • 44
  • 66
  • 2
    With the `/p:PublishSingleFile=true` option you get a single exe file. Example: `dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true` – Adriano Feb 24 '22 at 10:38