发布 .NET Core 时不会创建发布版本的文件夹

Folder for Release build does not get created when publishing .NET Core

您好,我正在使用 bash 脚本从源代码中获取 publish 文件夹并将其放入另一个应用程序的文件夹中。

问题是,当我使用 dotnet publish 时,publish 文件夹仅为 Debug 构建创建。
即使我的项目在 Release build set dotnet 命令为 Debug 生成。我做错了什么?

Bash 脚本

releasepath="D:\Work\redius\core\redius\bin\Release\netcoreapp2.1\publish" 
destpath="D:\dotpeek"
rediuspath="D:\Work\redius"
curDir="$(pwd)\out.txt"

if  [ ! -f curDir ]; 
then  
touch  $curDir
fi

echo $releasepath
rm -rf  $destpath
mkdir $destpath
(cd $rediuspath &&  dotnet publish | $curDir && echo "done publishing")
echo "Copying from : ${releasepath} to ${destpath}"
cp -rf  releasepath destpath
cd

我需要 script.I 第一行的文件夹已尝试使用 vstudio 中的 publish 但它创建了一个 nupkg 文件。

您必须使用 dotnet build -c Release 构建项目。然后就可以在Release模式下创建dll了。

dotnet publish先构建项目再发布。默认情况下使用构建配置 Debug

如果要使用构建配置 Release 构建项目,则必须指定 -c 标志。

dotnet publish -c Release

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore21

如果您需要指定额外的构建标志,您可以先构建项目然后发布它。

dotnet build -c Release
dotnet publish --no-build