如何在开发人员计算机上构建MSVS 2017 .NET Core .exe?(How to build MSVS 2017 .NET Core .exe on developer machine?)

编程入门 行业动态 更新时间:2024-10-24 19:26:18
如何在开发人员计算机上构建MSVS 2017 .NET Core .exe?(How to build MSVS 2017 .NET Core .exe on developer machine?)

有关TLDR,请参阅下面的编辑部分。

我使用了MSVS 2015社区并升级到MSVS 2017.我正在开发.NET Core控制台应用程序。 我在这里只讨论我的本地开发机器,它安装了MSVS并且安装了.NET Core运行时和SDK。

在MSVS 2015中,使用了project.json文件,默认情况下,构建过程在bin/Debug/netcoreapp1.1中生成了一个DLL文件,可以使用dotnet run命令dotnet run 。 但是有一个选项可以在project.json文件中做一个小调整:

... "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, ...

- >

... "Microsoft.NETCore.App": { "version": "1.0.1" }, ...

并添加一个runtimes ,如

"runtimes": { "win10-x64": {} }

如果你这样做并构建了你的项目,就会创建一个可以直接运行的EXE文件,而不使用dotnet run

现在问题是,使用csproj XML文件在MSVS 2017中是否可以? 更具体地说, 没有繁重的自包含部署是否可能 ? 我确实希望它没有完整的SDD发布,因为我在开发过程中使用这些可执行文件进行本地测试。 一旦项目发布,我就会进行SDD发布,但这在开发过程中非常不方便。

该项目已转换为MSVS 2017,但它只会再次生成DLL文件。 所以,我试图创建一个全新的空hello世界程序,并尝试从中获取EXE文件。 hello world csproj文件如下所示:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> </Project>

这只生成你可以运行dotnet run DLL文件。 可以对此进行更改:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks> </PropertyGroup> </Project>

这非常接近我想要的 - 生成一个EXE文件。 但是,这会创建运行.NET Framework 4.6的EXE文件,而不是.NET Core。 所以,它没有解决问题。 我真正想要的是.NET Core可执行文件而无需进行自包含部署。 可能吗?

编辑:刚刚发现这确实是可能的,我只是不知道如何在IDE中做到这一点。 如果我在IDE中Ctrl+Alt+F7 ,当前会发生与命令相同的结果

dotnet build --configuration Debug

我想要的东西可以通过命令生成

dotnet build --configuration Debug --runtime win10-x64

所以我现在真正想要的是修改默认的IDE构建命令,以使用--runtime win10-x64参数复制此行为。

Please see EDIT section below for TLDR.

I used MSVS 2015 Community and upgraded to MSVS 2017. I am developing .NET Core console application. I am talking here only about my local development machine, which has MSVS installed and it has .NET Core runtimes and SDKs installed.

In MSVS 2015, project.json files were used, and by default the build process produced a DLL file in the bin/Debug/netcoreapp1.1, that one could run using dotnet run command. But there was an option to make a minor tweak in the project.json file:

... "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, ...

->

... "Microsoft.NETCore.App": { "version": "1.0.1" }, ...

and adding a runtimes section, such as

"runtimes": { "win10-x64": {} }

and if you did this and built your project, an EXE file was created that you could run directly, without using dotnet run.

Now the question is, is the same possible in MSVS 2017 using csproj XML files? And more specifically, is it possible without the heavy self-contained deployments? I do want it without the full SDD publish because I use these executables for just local testing during the development. Once the project is to be released, I do the SDD publish, but that is very inconvenient during the development process.

The project was converted to MSVS 2017, but it only generates DLL files again. So, I tried to create a completely new and empty hello world program and try to get EXE file from it. The hello world csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> </Project>

this only generates DLL file that you can run with dotnet run. It is possible to make a change to this:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks> </PropertyGroup> </Project>

which is very close to what I want - generating an EXE file. However, this creates EXE file that runs .NET Framework 4.6, not .NET Core. So, it does not solve the problem. What I really want is .NET Core executable without having to do self-contained deployment. Is it possible?

EDIT: Just found out that this is indeed possible, I just don't know how to do it in IDE. What currently happens if I hit Ctrl+Alt+F7 in IDE produces the same result as command

dotnet build --configuration Debug

and what I want can be produced by command

dotnet build --configuration Debug --runtime win10-x64

So what I really want now is modify the default IDE build command to replicate this behavior with --runtime win10-x64 parameter.

最满意答案

在.NET Core中,如果您想在dotnet build期间生成.exe ,则需要提供您希望为其构建可执行文件的运行时。

在project.json中,您通过删除type: platform并添加runtimes部分来完成上述操作。

在.csproj中,您可以通过指定名为RuntimeIdentifier的MSBuild属性来完成此RuntimeIdentifier 。 在命令行中,当你说dotnet build --runtime win10-x64 , - --runtime值传递给MSBuild具有RuntimeIdentifier属性。

一个选项是你可以在.csproj中纯粹设置RuntimeIdentifier :

<PropertyGroup> <RuntimeIdentifier>win10-x64</RuntimeIdentifier> </PropertyGroup>

现在,当您在VS中构建时,它将在构建输出文件夹中生成.exe 。

另外

我不确定你是否对此感兴趣,但听起来你只想要一种方法来运行你的应用程序而不需要调用dotnet run 。 如果是这样,则根本不需要设置运行时。 默认情况下,您的应用程序内置到bin\Debug\netcoreapp1.1\AppName.dll 。 您可以通过说dotnet bin\Debug\netcoreapp1.1\AppName.dll来运行您的应用程序,这基本上就是dotnet run的内容。

In .NET Core, if you want an .exe produced during dotnet build, you need to supply the runtime that you want the executable built for.

In project.json, you did it as you describe above by removing type: platform and adding a runtimes section.

In .csproj, you do it by specifying the MSBuild property named RuntimeIdentifier. On the command-line, when you say dotnet build --runtime win10-x64, the --runtime value gets passed into MSBuild has the RuntimeIdentifier property.

One option is you can purely set the RuntimeIdentifier in your .csproj:

<PropertyGroup> <RuntimeIdentifier>win10-x64</RuntimeIdentifier> </PropertyGroup>

Now when you build in VS, it will produce an .exe in the build output folder.

Alternatively

I'm not sure if you are interested in this or not, but it sounds like you just want a way to run your application without calling dotnet run. If this is true, you don't need to set a runtime at all. By default your application gets built into bin\Debug\netcoreapp1.1\AppName.dll. You can run your application by saying dotnet bin\Debug\netcoreapp1.1\AppName.dll, which is basically what dotnet run does under the covers.

更多推荐

本文发布于:2023-07-15 18:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机上   开发人员   如何在   MSVS   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!