为什么 VSCode 中的 .Net Core CLI 将发布文件夹放在调试目录中
Why does .Net Core CLI in VSCode put release folder in the debug directory
我觉得我遗漏了一些明显的东西,但是搜索 google,这个站点和 GitHub 上的 .Net Core SLI 问题部分没有立即 return 一个答案,也没有阅读 .Net Core project.json 格式的文档。
在由 Visual Studio(而非 VSCode)构建的普通旧 C# 项目(常规 .Net,而非 Core)中,通常 运行 构建会将文件放入
%project root%/bin/Debug
开箱即用,或
%project root%/bin/Release
如果您选择发布。
在 VSCode 中使用 .Net Core,默认情况下构建将文件放入
%project root%/bin/Debug/netcoreapp1.0.
但是如果你 运行
dotnet publish
在命令行中,它会将文件放在
中的发布文件夹中
%project root%/bin/Debug/netcoreapp1.0.
导致类似
的结构
%project root%/bin/Debug/netcoreapp1.0/release.
如果您在 project.json 中指定为特定平台目标构建,那么它同样会将文件放入
%project root%/bin/Debug/netcoreapp1.0/PlatformName.
例如
%project root%/bin/Debug/netcoreapp1.0/win7-x64.
我的问题是,为什么.Net Core 将发布文件夹放在调试文件夹中,因为我更喜欢旧的目录结构,有什么方法可以告诉 .Net这样做的核心是通过一些 project.json 属性 或 cli 标志,类似于 typescript 允许您指定 outDir?
使用 'dotnet new' 提供的默认 hello world 项目进行测试,我修改后的 project.json 如下所示:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"runtimes": {
"win7-x64": { }
}
}
根据 documentation(粗体是我的):
dotnet publish [--framework] [--runtime] [--build-base-path] [--output] [--version-suffix] [--configuration] []
...
-c, --configuration [Debug|Release]
Configuration to use when publishing. The default value is Debug.
所以你需要使用:
dotnet publish -c Release
(还有用于指定目标文件夹的 --output
参数:文档还说明了默认值,这与您所看到的相匹配)
我觉得我遗漏了一些明显的东西,但是搜索 google,这个站点和 GitHub 上的 .Net Core SLI 问题部分没有立即 return 一个答案,也没有阅读 .Net Core project.json 格式的文档。
在由 Visual Studio(而非 VSCode)构建的普通旧 C# 项目(常规 .Net,而非 Core)中,通常 运行 构建会将文件放入
%project root%/bin/Debug
开箱即用,或
%project root%/bin/Release
如果您选择发布。
在 VSCode 中使用 .Net Core,默认情况下构建将文件放入
%project root%/bin/Debug/netcoreapp1.0.
但是如果你 运行
dotnet publish
在命令行中,它会将文件放在
中的发布文件夹中%project root%/bin/Debug/netcoreapp1.0.
导致类似
的结构%project root%/bin/Debug/netcoreapp1.0/release.
如果您在 project.json 中指定为特定平台目标构建,那么它同样会将文件放入
%project root%/bin/Debug/netcoreapp1.0/PlatformName.
例如
%project root%/bin/Debug/netcoreapp1.0/win7-x64.
我的问题是,为什么.Net Core 将发布文件夹放在调试文件夹中,因为我更喜欢旧的目录结构,有什么方法可以告诉 .Net这样做的核心是通过一些 project.json 属性 或 cli 标志,类似于 typescript 允许您指定 outDir?
使用 'dotnet new' 提供的默认 hello world 项目进行测试,我修改后的 project.json 如下所示:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"runtimes": {
"win7-x64": { }
}
}
根据 documentation(粗体是我的):
dotnet publish [--framework] [--runtime] [--build-base-path] [--output] [--version-suffix] [--configuration] []
...
-c, --configuration [Debug|Release]
Configuration to use when publishing. The default value is Debug.
所以你需要使用:
dotnet publish -c Release
(还有用于指定目标文件夹的 --output
参数:文档还说明了默认值,这与您所看到的相匹配)