c# - dotnet 发布时如何更改 dll 名称?

标签 c# docker .net-core dockerfile .net-3.0

除了最后一行之外,我所有的 .net 核心 dockerfile 都是 99% 相同的:ENTRYPOINT ["dotnet", "<APP NAME HERE>.dll"]我似乎很愚蠢,因为否则它们可能都是相同的
有没有办法用 dotnet publish -c Release -o out 更改 dll 名称命令?我可以这样做而不必修改 csproj 文件或任何东西吗?

最佳答案

您可以使用此命令来执行构建并重命名程序集:

dotnet msbuild -r -p:Configuration=Release;AssemblyName=foo
在 Linux/macOS 上,您必须在命令周围添加引号,如下所示:
dotnet msbuild -r '-p:Configuration=Release;AssemblyName=foo'
但是,由于 global property,可能会出现意想不到的副作用。正在设置。您应该从 2019 年 9 月开始阅读这个 Unresolved 问题,因为它直接回答了您关于 Docker 和重命名输出的问题:https://github.com/dotnet/msbuild/issues/4696
另外,我知道您想避免编辑 .csproj 文件,但如果您不知道,您可以添加 AssemblyName属性并以这种方式设置输出名称。
如:
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AssemblyName>foo</AssemblyName>
  </PropertyGroup>
这将创建 foo.dll (以及其他文件,例如 .pdb.deps.json 等)

关于c# - dotnet 发布时如何更改 dll 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64761685/

相关文章:

Jenkins 作业 : ignore error

c# - 未经授权的错误机器人框架

c# - 为什么8位字节中的~1等于-2?

docker - Hyperledger Fabric v2 新链代码生命周期安装问题与 dind vm 端点 + tls

python - 无法从 docker compose env 文件访问环境变量

c# - NSubstitute ILogger .NET Core

c# - 在 Visual Studio Code for Mac 上找不到类型或命名空间名称 'System'

c# - 在 .Net Core 中加载程序集时解决依赖关系

c# - Resharper Trap "Convert to ' return'语句”

c# - 面对序列化问题