Build .NET Core console application to output an EXE?How to generate .exe C# file in Visual StudioVisual Studio .NET Core Builds a .DLL and not a .EXEHow to publish .NET Core console app's .exe in Rider?Visual Studio Code builds DLL (OutputType is Exe)How to run .NET Core console app from the command lineVS2017 Compile NetCoreApp as EXEHow to create exe of a console application.net core cross platform desktop appDeploy .NET Core 2 Console AppVisual Studio won't build to exe (.NET Core 2.0)Build .exe file in .NET Core RC2Why does .Net Core CLI in VSCode put release folder in the debug directoryDebug .NET Core Console Application with VS2015Build .Net Core as an EXE not a DLLUsing .NET Core library in .NET 4.5.2 console applicationWhat is the difference between .NET Core and .NET Standard Class Library project types?FileNotFoundException when referencing DLL in .NET Core Application.NET Core output directory does not include platformUpgrading to .NET Core 2.0: PackageTargetFallback and AssetTargetFallback cannot be used togetherInstalling Dot Net Core 2.1 on build server
Understanding the as-if rule, "the program was executed as written"
Why didn't Avengers simply jump 5 years back?
Why did the Apple IIe make a hideous noise if you inserted the disk upside down?
Installed software from source, how to say yum not to install it from package?
Could you fall off a planet if it was being accelerated by engines?
What is the lowest possible AC?
Why would Dementors torture a Death Eater if they are loyal to Voldemort?
Find the closest three-digit hex colour
A quine of sorts
What would you need merely the term "collection" for pitches, but not "scale"?
What is my external HDD doing?
Tricolour nonogram
Why will we fail creating a self sustaining off world colony?
Is this house-rule removing the increased effect of cantrips at higher character levels balanced?
How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?
Why am I getting an electric shock from the water in my hot tub?
Identifying positions of the last TRUEs in a sequence of TRUEs and FALSEs
What was the point of separating stdout and stderr?
What prevents a US state from colonizing a smaller state?
Why is my 401k manager recommending me to save more?
Calculus, water poured into a cone: Why is the derivative non-linear?
Is it possible to alias a column based on the result of a select+where?
Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?
Why didn't Caesar move against Sextus Pompey immediately after Munda?
Build .NET Core console application to output an EXE?
How to generate .exe C# file in Visual StudioVisual Studio .NET Core Builds a .DLL and not a .EXEHow to publish .NET Core console app's .exe in Rider?Visual Studio Code builds DLL (OutputType is Exe)How to run .NET Core console app from the command lineVS2017 Compile NetCoreApp as EXEHow to create exe of a console application.net core cross platform desktop appDeploy .NET Core 2 Console AppVisual Studio won't build to exe (.NET Core 2.0)Build .exe file in .NET Core RC2Why does .Net Core CLI in VSCode put release folder in the debug directoryDebug .NET Core Console Application with VS2015Build .Net Core as an EXE not a DLLUsing .NET Core library in .NET 4.5.2 console applicationWhat is the difference between .NET Core and .NET Standard Class Library project types?FileNotFoundException when referencing DLL in .NET Core Application.NET Core output directory does not include platformUpgrading to .NET Core 2.0: PackageTargetFallback and AssetTargetFallback cannot be used togetherInstalling Dot Net Core 2.1 on build server
For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. Project runs fine in debug.
I've tried publishing the project but that does not work either. Makes sense since .exe would be platform-specific, but there must be a way. My searches have only turned up reference to older .Net Core versions that used project.json.
Whenever I build or publish, this is all I get.
.net-core
add a comment |
For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. Project runs fine in debug.
I've tried publishing the project but that does not work either. Makes sense since .exe would be platform-specific, but there must be a way. My searches have only turned up reference to older .Net Core versions that used project.json.
Whenever I build or publish, this is all I get.
.net-core
13
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
1
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by sayingdotnet <path>.dll
(I was not thinking and typingdotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)
– Ruben Bartelink
Oct 31 '18 at 9:14
add a comment |
For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. Project runs fine in debug.
I've tried publishing the project but that does not work either. Makes sense since .exe would be platform-specific, but there must be a way. My searches have only turned up reference to older .Net Core versions that used project.json.
Whenever I build or publish, this is all I get.
.net-core
For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. Project runs fine in debug.
I've tried publishing the project but that does not work either. Makes sense since .exe would be platform-specific, but there must be a way. My searches have only turned up reference to older .Net Core versions that used project.json.
Whenever I build or publish, this is all I get.
.net-core
.net-core
asked May 19 '17 at 15:43
kenchiladakenchilada
3,8243 gold badges19 silver badges31 bronze badges
3,8243 gold badges19 silver badges31 bronze badges
13
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
1
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by sayingdotnet <path>.dll
(I was not thinking and typingdotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)
– Ruben Bartelink
Oct 31 '18 at 9:14
add a comment |
13
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
1
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by sayingdotnet <path>.dll
(I was not thinking and typingdotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)
– Ruben Bartelink
Oct 31 '18 at 9:14
13
13
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
1
1
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by saying
dotnet <path>.dll
(I was not thinking and typing dotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)– Ruben Bartelink
Oct 31 '18 at 9:14
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by saying
dotnet <path>.dll
(I was not thinking and typing dotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)– Ruben Bartelink
Oct 31 '18 at 9:14
add a comment |
5 Answers
5
active
oldest
votes
For debugging purposes, you can use the dll file. You can run it using dotnet ConsoleApp2.dll
. If you want to generate an exe, you have to generate a self-contained application.
To generate a self-contained application (exe in windows), you must specify the target runtime (which is specific to the OS you target).
Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the csproj (list of supported rid):
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
The above step is no longer required starting with .NET Core 2.0.
Then, set the desired runtime when you publish your application:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set theRuntimeIdentifier
in the csproj.
– meziantou
Sep 14 '17 at 13:52
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
|
show 13 more comments
For anyone that's using Visual Studio and wants to do this via GUI, see the steps below:
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
add a comment |
The following will produce, in the output directory,
- all the package references
- the output assembly
- the bootstrapping exe
But does not contain all netcore runtime assemblies
<PropertyGroup>
<Temp>$(SolutionDir)packaging</Temp>
</PropertyGroup>
<ItemGroup>
<BootStrapFiles Include="$(Temp)hostpolicy.dll;$(Temp)$(ProjectName).exe;$(Temp)hostfxr.dll;"/>
</ItemGroup>
<Target Name="GenerateNetcoreExe"
AfterTargets="Build"
Condition="'$(IsNestedBuild)' != 'true'">
<RemoveDir Directories="$(Temp)" />
<Exec
ConsoleToMSBuild="true"
Command="dotnet build $(ProjectPath) -r win-x64 /p:CopyLocalLockFileAssemblies=false;IsNestedBuild=true --output $(Temp)" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Copy
SourceFiles="@(BootStrapFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
i wrapped it up in a sample here https://github.com/SimonCropp/NetCoreConsole
add a comment |
If a .bat file is acceptable, you can create a bat file with the same name as the dll (and place it in the same folder), then paste in the following content:
dotnet %0.dll %*
Obviously, this assumes that the machine has .NET Core installed.
Call it without the '.bat' part. i.e.: c:>"pathtoprogram" -args blah
(this answer is derived from Chet's comment)
add a comment |
Here's my hacky workaround - generate a Console Application (.NET Framework) that reads its own name and args, then calls dotnet [nameOfExe].dll [args]
Of course this assumes that dotnet is installed on the target machine.
Here's the code, feel free to copy!
using System;
using System.Diagnostics;
using System.Text;
namespace dotNetLauncher
class Program
/*
If you make .net core apps, they have to be launched like dotnet blah.dll args here
This is a convenience exe that launches .net core apps via name.exe
Just rename the output exe to the name of the .net core dll you wish to launch
*/
static void Main(string[] args)
var exePath = AppDomain.CurrentDomain.BaseDirectory;
var exeName = AppDomain.CurrentDomain.FriendlyName;
var assemblyName = exeName.Substring(0, exeName.Length - 4);
StringBuilder passInArgs = new StringBuilder();
foreach(var arg in args)
bool needsSurroundingQuotes = false;
if (arg.Contains(" ")
string callingArgs = $""exePathassemblyName.dll" passInArgs.ToString().Trim()";
var p = new Process
StartInfo = new ProcessStartInfo("dotnet", callingArgs)
UseShellExecute = false
;
p.Start();
p.WaitForExit();
2
If you are going to have an additional file anyway, why not just create a bat file that containsdotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44074121%2fbuild-net-core-console-application-to-output-an-exe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
For debugging purposes, you can use the dll file. You can run it using dotnet ConsoleApp2.dll
. If you want to generate an exe, you have to generate a self-contained application.
To generate a self-contained application (exe in windows), you must specify the target runtime (which is specific to the OS you target).
Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the csproj (list of supported rid):
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
The above step is no longer required starting with .NET Core 2.0.
Then, set the desired runtime when you publish your application:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set theRuntimeIdentifier
in the csproj.
– meziantou
Sep 14 '17 at 13:52
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
|
show 13 more comments
For debugging purposes, you can use the dll file. You can run it using dotnet ConsoleApp2.dll
. If you want to generate an exe, you have to generate a self-contained application.
To generate a self-contained application (exe in windows), you must specify the target runtime (which is specific to the OS you target).
Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the csproj (list of supported rid):
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
The above step is no longer required starting with .NET Core 2.0.
Then, set the desired runtime when you publish your application:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set theRuntimeIdentifier
in the csproj.
– meziantou
Sep 14 '17 at 13:52
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
|
show 13 more comments
For debugging purposes, you can use the dll file. You can run it using dotnet ConsoleApp2.dll
. If you want to generate an exe, you have to generate a self-contained application.
To generate a self-contained application (exe in windows), you must specify the target runtime (which is specific to the OS you target).
Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the csproj (list of supported rid):
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
The above step is no longer required starting with .NET Core 2.0.
Then, set the desired runtime when you publish your application:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
For debugging purposes, you can use the dll file. You can run it using dotnet ConsoleApp2.dll
. If you want to generate an exe, you have to generate a self-contained application.
To generate a self-contained application (exe in windows), you must specify the target runtime (which is specific to the OS you target).
Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the csproj (list of supported rid):
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
The above step is no longer required starting with .NET Core 2.0.
Then, set the desired runtime when you publish your application:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
edited Apr 6 at 13:16
Raj Narayanan
315 bronze badges
315 bronze badges
answered May 19 '17 at 15:53
meziantoumeziantou
14.2k4 gold badges36 silver badges50 bronze badges
14.2k4 gold badges36 silver badges50 bronze badges
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set theRuntimeIdentifier
in the csproj.
– meziantou
Sep 14 '17 at 13:52
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
|
show 13 more comments
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set theRuntimeIdentifier
in the csproj.
– meziantou
Sep 14 '17 at 13:52
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
13
13
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set the
RuntimeIdentifier
in the csproj.– meziantou
Sep 14 '17 at 13:52
I think this can be done only with the CLI. BTW, starting with .net core 2, you don't need to set the
RuntimeIdentifier
in the csproj.– meziantou
Sep 14 '17 at 13:52
21
21
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
for .NET Core 2.0 can this be done in Visual Studio? Or I must type these commands by hand?
– Tomasz Sikora
Oct 21 '17 at 14:16
57
57
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
Over 60MB for a Hello world console app!
– shox
Jan 23 '18 at 5:16
12
12
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
@mikolaj There's just one target runtime "portable". Is there a way to bring all the targets in? I'm ok with to use the command line, however think that's a step back.
– gsharp
Jan 24 '18 at 7:35
9
9
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
Here's a list of the available runtime identifiers (e.g. win10-x64, linux-x64, etc): docs.microsoft.com/en-us/dotnet/core/rid-catalog
– J.D. Mallen
Apr 25 '18 at 17:41
|
show 13 more comments
For anyone that's using Visual Studio and wants to do this via GUI, see the steps below:
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
add a comment |
For anyone that's using Visual Studio and wants to do this via GUI, see the steps below:
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
add a comment |
For anyone that's using Visual Studio and wants to do this via GUI, see the steps below:
For anyone that's using Visual Studio and wants to do this via GUI, see the steps below:
answered Apr 20 at 16:15
Francisco VilchesFrancisco Vilches
4145 silver badges8 bronze badges
4145 silver badges8 bronze badges
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
add a comment |
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
5
5
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
Too bad the output is a bunch of files, not just one EXE like the old .NET Framework.
– Tomas Karban
Apr 29 at 15:29
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
@Tomas Karban - It was the case until I changed deployment mode to "self-contained" After change exe file appeared in the publish folder also :-)
– Mariusz
Jun 18 at 15:44
add a comment |
The following will produce, in the output directory,
- all the package references
- the output assembly
- the bootstrapping exe
But does not contain all netcore runtime assemblies
<PropertyGroup>
<Temp>$(SolutionDir)packaging</Temp>
</PropertyGroup>
<ItemGroup>
<BootStrapFiles Include="$(Temp)hostpolicy.dll;$(Temp)$(ProjectName).exe;$(Temp)hostfxr.dll;"/>
</ItemGroup>
<Target Name="GenerateNetcoreExe"
AfterTargets="Build"
Condition="'$(IsNestedBuild)' != 'true'">
<RemoveDir Directories="$(Temp)" />
<Exec
ConsoleToMSBuild="true"
Command="dotnet build $(ProjectPath) -r win-x64 /p:CopyLocalLockFileAssemblies=false;IsNestedBuild=true --output $(Temp)" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Copy
SourceFiles="@(BootStrapFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
i wrapped it up in a sample here https://github.com/SimonCropp/NetCoreConsole
add a comment |
The following will produce, in the output directory,
- all the package references
- the output assembly
- the bootstrapping exe
But does not contain all netcore runtime assemblies
<PropertyGroup>
<Temp>$(SolutionDir)packaging</Temp>
</PropertyGroup>
<ItemGroup>
<BootStrapFiles Include="$(Temp)hostpolicy.dll;$(Temp)$(ProjectName).exe;$(Temp)hostfxr.dll;"/>
</ItemGroup>
<Target Name="GenerateNetcoreExe"
AfterTargets="Build"
Condition="'$(IsNestedBuild)' != 'true'">
<RemoveDir Directories="$(Temp)" />
<Exec
ConsoleToMSBuild="true"
Command="dotnet build $(ProjectPath) -r win-x64 /p:CopyLocalLockFileAssemblies=false;IsNestedBuild=true --output $(Temp)" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Copy
SourceFiles="@(BootStrapFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
i wrapped it up in a sample here https://github.com/SimonCropp/NetCoreConsole
add a comment |
The following will produce, in the output directory,
- all the package references
- the output assembly
- the bootstrapping exe
But does not contain all netcore runtime assemblies
<PropertyGroup>
<Temp>$(SolutionDir)packaging</Temp>
</PropertyGroup>
<ItemGroup>
<BootStrapFiles Include="$(Temp)hostpolicy.dll;$(Temp)$(ProjectName).exe;$(Temp)hostfxr.dll;"/>
</ItemGroup>
<Target Name="GenerateNetcoreExe"
AfterTargets="Build"
Condition="'$(IsNestedBuild)' != 'true'">
<RemoveDir Directories="$(Temp)" />
<Exec
ConsoleToMSBuild="true"
Command="dotnet build $(ProjectPath) -r win-x64 /p:CopyLocalLockFileAssemblies=false;IsNestedBuild=true --output $(Temp)" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Copy
SourceFiles="@(BootStrapFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
i wrapped it up in a sample here https://github.com/SimonCropp/NetCoreConsole
The following will produce, in the output directory,
- all the package references
- the output assembly
- the bootstrapping exe
But does not contain all netcore runtime assemblies
<PropertyGroup>
<Temp>$(SolutionDir)packaging</Temp>
</PropertyGroup>
<ItemGroup>
<BootStrapFiles Include="$(Temp)hostpolicy.dll;$(Temp)$(ProjectName).exe;$(Temp)hostfxr.dll;"/>
</ItemGroup>
<Target Name="GenerateNetcoreExe"
AfterTargets="Build"
Condition="'$(IsNestedBuild)' != 'true'">
<RemoveDir Directories="$(Temp)" />
<Exec
ConsoleToMSBuild="true"
Command="dotnet build $(ProjectPath) -r win-x64 /p:CopyLocalLockFileAssemblies=false;IsNestedBuild=true --output $(Temp)" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Copy
SourceFiles="@(BootStrapFiles)"
DestinationFolder="$(OutputPath)"
/>
</Target>
i wrapped it up in a sample here https://github.com/SimonCropp/NetCoreConsole
edited Oct 19 '18 at 12:21
Frederik Struck-Schøning
10.1k7 gold badges47 silver badges54 bronze badges
10.1k7 gold badges47 silver badges54 bronze badges
answered Oct 4 '18 at 1:17
SimonSimon
22.2k15 gold badges108 silver badges169 bronze badges
22.2k15 gold badges108 silver badges169 bronze badges
add a comment |
add a comment |
If a .bat file is acceptable, you can create a bat file with the same name as the dll (and place it in the same folder), then paste in the following content:
dotnet %0.dll %*
Obviously, this assumes that the machine has .NET Core installed.
Call it without the '.bat' part. i.e.: c:>"pathtoprogram" -args blah
(this answer is derived from Chet's comment)
add a comment |
If a .bat file is acceptable, you can create a bat file with the same name as the dll (and place it in the same folder), then paste in the following content:
dotnet %0.dll %*
Obviously, this assumes that the machine has .NET Core installed.
Call it without the '.bat' part. i.e.: c:>"pathtoprogram" -args blah
(this answer is derived from Chet's comment)
add a comment |
If a .bat file is acceptable, you can create a bat file with the same name as the dll (and place it in the same folder), then paste in the following content:
dotnet %0.dll %*
Obviously, this assumes that the machine has .NET Core installed.
Call it without the '.bat' part. i.e.: c:>"pathtoprogram" -args blah
(this answer is derived from Chet's comment)
If a .bat file is acceptable, you can create a bat file with the same name as the dll (and place it in the same folder), then paste in the following content:
dotnet %0.dll %*
Obviously, this assumes that the machine has .NET Core installed.
Call it without the '.bat' part. i.e.: c:>"pathtoprogram" -args blah
(this answer is derived from Chet's comment)
edited Feb 28 at 0:47
answered Feb 28 at 0:11
Ambrose LeungAmbrose Leung
1,37810 silver badges18 bronze badges
1,37810 silver badges18 bronze badges
add a comment |
add a comment |
Here's my hacky workaround - generate a Console Application (.NET Framework) that reads its own name and args, then calls dotnet [nameOfExe].dll [args]
Of course this assumes that dotnet is installed on the target machine.
Here's the code, feel free to copy!
using System;
using System.Diagnostics;
using System.Text;
namespace dotNetLauncher
class Program
/*
If you make .net core apps, they have to be launched like dotnet blah.dll args here
This is a convenience exe that launches .net core apps via name.exe
Just rename the output exe to the name of the .net core dll you wish to launch
*/
static void Main(string[] args)
var exePath = AppDomain.CurrentDomain.BaseDirectory;
var exeName = AppDomain.CurrentDomain.FriendlyName;
var assemblyName = exeName.Substring(0, exeName.Length - 4);
StringBuilder passInArgs = new StringBuilder();
foreach(var arg in args)
bool needsSurroundingQuotes = false;
if (arg.Contains(" ")
string callingArgs = $""exePathassemblyName.dll" passInArgs.ToString().Trim()";
var p = new Process
StartInfo = new ProcessStartInfo("dotnet", callingArgs)
UseShellExecute = false
;
p.Start();
p.WaitForExit();
2
If you are going to have an additional file anyway, why not just create a bat file that containsdotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
add a comment |
Here's my hacky workaround - generate a Console Application (.NET Framework) that reads its own name and args, then calls dotnet [nameOfExe].dll [args]
Of course this assumes that dotnet is installed on the target machine.
Here's the code, feel free to copy!
using System;
using System.Diagnostics;
using System.Text;
namespace dotNetLauncher
class Program
/*
If you make .net core apps, they have to be launched like dotnet blah.dll args here
This is a convenience exe that launches .net core apps via name.exe
Just rename the output exe to the name of the .net core dll you wish to launch
*/
static void Main(string[] args)
var exePath = AppDomain.CurrentDomain.BaseDirectory;
var exeName = AppDomain.CurrentDomain.FriendlyName;
var assemblyName = exeName.Substring(0, exeName.Length - 4);
StringBuilder passInArgs = new StringBuilder();
foreach(var arg in args)
bool needsSurroundingQuotes = false;
if (arg.Contains(" ")
string callingArgs = $""exePathassemblyName.dll" passInArgs.ToString().Trim()";
var p = new Process
StartInfo = new ProcessStartInfo("dotnet", callingArgs)
UseShellExecute = false
;
p.Start();
p.WaitForExit();
2
If you are going to have an additional file anyway, why not just create a bat file that containsdotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
add a comment |
Here's my hacky workaround - generate a Console Application (.NET Framework) that reads its own name and args, then calls dotnet [nameOfExe].dll [args]
Of course this assumes that dotnet is installed on the target machine.
Here's the code, feel free to copy!
using System;
using System.Diagnostics;
using System.Text;
namespace dotNetLauncher
class Program
/*
If you make .net core apps, they have to be launched like dotnet blah.dll args here
This is a convenience exe that launches .net core apps via name.exe
Just rename the output exe to the name of the .net core dll you wish to launch
*/
static void Main(string[] args)
var exePath = AppDomain.CurrentDomain.BaseDirectory;
var exeName = AppDomain.CurrentDomain.FriendlyName;
var assemblyName = exeName.Substring(0, exeName.Length - 4);
StringBuilder passInArgs = new StringBuilder();
foreach(var arg in args)
bool needsSurroundingQuotes = false;
if (arg.Contains(" ")
string callingArgs = $""exePathassemblyName.dll" passInArgs.ToString().Trim()";
var p = new Process
StartInfo = new ProcessStartInfo("dotnet", callingArgs)
UseShellExecute = false
;
p.Start();
p.WaitForExit();
Here's my hacky workaround - generate a Console Application (.NET Framework) that reads its own name and args, then calls dotnet [nameOfExe].dll [args]
Of course this assumes that dotnet is installed on the target machine.
Here's the code, feel free to copy!
using System;
using System.Diagnostics;
using System.Text;
namespace dotNetLauncher
class Program
/*
If you make .net core apps, they have to be launched like dotnet blah.dll args here
This is a convenience exe that launches .net core apps via name.exe
Just rename the output exe to the name of the .net core dll you wish to launch
*/
static void Main(string[] args)
var exePath = AppDomain.CurrentDomain.BaseDirectory;
var exeName = AppDomain.CurrentDomain.FriendlyName;
var assemblyName = exeName.Substring(0, exeName.Length - 4);
StringBuilder passInArgs = new StringBuilder();
foreach(var arg in args)
bool needsSurroundingQuotes = false;
if (arg.Contains(" ")
string callingArgs = $""exePathassemblyName.dll" passInArgs.ToString().Trim()";
var p = new Process
StartInfo = new ProcessStartInfo("dotnet", callingArgs)
UseShellExecute = false
;
p.Start();
p.WaitForExit();
edited May 31 at 16:58
Chris Stillwell
7,0007 gold badges49 silver badges60 bronze badges
7,0007 gold badges49 silver badges60 bronze badges
answered Jan 16 at 20:18
Ambrose LeungAmbrose Leung
1,37810 silver badges18 bronze badges
1,37810 silver badges18 bronze badges
2
If you are going to have an additional file anyway, why not just create a bat file that containsdotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
add a comment |
2
If you are going to have an additional file anyway, why not just create a bat file that containsdotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
2
2
If you are going to have an additional file anyway, why not just create a bat file that contains
dotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
If you are going to have an additional file anyway, why not just create a bat file that contains
dotnet [nameOfExe].dll %*
– Chet
Feb 27 at 0:36
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
That's a good idea as well. I'll add another answer.
– Ambrose Leung
Feb 28 at 0:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44074121%2fbuild-net-core-console-application-to-output-an-exe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
13
Possible duplicate of VS2017 Compile NetCoreApp as EXE
– Martin Ullrich
May 19 '17 at 16:20
1
@geekzster please undelete - I know you didnt answer the OP question, but you answered mine, and I suspect that of many others by saying
dotnet <path>.dll
(I was not thinking and typingdotnet run <path>.dll
without success for obvious reasons) ! (On reflection it would be good if this was closed in favor of the other question which has a similar set of answers)– Ruben Bartelink
Oct 31 '18 at 9:14