本文介绍了dotnet build 如何选择输出名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先解释一下导致这个问题的原因.

First, let me explain the problem that causes this question.

如果我使用 dotnet new 创建一个新项目并使用 -n arg 指定一个随机项目名称,那么在执行 dotnet restore 之后 -dotnet build 从默认 bash 终端 -> 最终输出名称是 always React + .output_type.喜欢:

If I create a new project using dotnet new and specifying a random project name with -n arg, then after doing dotnet restore - dotnet build from default bash terminal -> the final output name is always React + .output_type. Like:

/bin/Debug/netcoreapp2.0/React.dll

我没有为 dotnet 命令指定任何额外的参数.看起来选择什么类型的项目并不重要:我已经尝试过 consolewebapi.

I don't specify any additional arguments with dotnet commands. And looks like it doesn't matter what type of project to select: I have tried with console and webapi.

但我发现,如果我在 VS Code 中打开项目并从 VS Code 终端(也是 bash)执行相同的 dotnet build 命令-> 输出名称是正确的并且等于project_name+.output_type.

But I have found that if I open the project in VS Code and do the same dotnet build command from VS Code terminal (that is also bash) -> the output name is correct and equal to the project_name+.output_type.

所以之前我认为在构建过程中输出名称总是取自 .csproj 文件名.但现在看起来有些东西可以覆盖这种行为:不同的终端 - 不同的环境设置等.

So before I thought that output name is always taken from .csproj file name during building. But now it looks like something could override this behavior: different terminals - different env settings, etc.

因为输出名称包含 React 我在责怪 react cli 工具,但这并不能帮助我确定名称覆盖的原因.

Cause output name contains React I am blaming the react cli tooling, but this doesn't help me with identifying the reason of name-override.

我从两个终端都做了 dotnet --info 并且输出是一样的:

I did dotnet --info from both terminals and output was the same:

.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.0.0/

推荐答案

感谢 @MartinUllrich,我发现 $TARGETNAME 变量覆盖了项目名称.删除变量解决问题:

Thanks to @MartinUllrich, I have found that $TARGETNAME variable overrides the project name. Removing variable fix the problem:

> unset TARGETNAME

这篇关于dotnet build 如何选择输出名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 15:43