简体   繁体   English

发布时如何定位特定的.NET Core Runtimes?

[英]When publishing how do I target specific .NET Core Runtimes?

When I publish my .NET Core app, it outputs a runtimes directory with the following sub-directories: 当我发布我的.NET Core应用程序时,它会输出一个带有以下子目录的runtimes目录:

- publish/runtimes/
   - debian.8-x64/
   - fedora.23-x64/
   - fedora.24-x64/
   - opensuse.13.2-x64/
   - opensuse.42.1-x64/
   - osx/
   - osx.10.10-x64/
   - rhel.7-x64/
   - ubuntu.14.04-x64/
   - ubuntu.16.04-x64/
   - ubuntu.16.10-x64/
   - unix/
   - win/

On my CI/CD server I publish my applications with this command: 在我的CI / CD服务器上,我使用以下命令发布我的应用程序:

dotnet publish -c Release -o ..\publish

My publish settings in the project file are the following: 我在项目文件中的发布设置如下:

  • Target Framework: netcoreapp2.1 目标框架:netcoreapp2.1
  • Deployment Mode: Framework-Dependent 部署模式:依赖于框架
  • Target Runtime: win-x64 目标运行时:win-x64

I only plan to publish this application on Windows 2016 Server so the OSX/Linux/Unix runtimes folders are not necessary. 我只计划在Windows 2016 Server上发布此应用程序,因此不需要OSX / Linux / Unix runtimes文件夹。 Worse in several cases these runtimes folders contain known vulnerable dlls which lead to false positive OSA scans. 更糟糕的是,在某些情况下,这些runtimes文件夹包含已知的易受攻击的dlls ,这会导致误报OSA扫描。

Is there a way to configure the project to only output the win runtime folder? 有没有办法将项目配置为仅输出win运行时文件夹?

Update 更新

I have tried the suggestions by @ahsteele and the output of adding the RIDs to my csproj files is the same as if I did not specify the RIDs. 我已经尝试了@ahsteele的建议,并且将RID添加到我的csproj文件的输出与我没有指定RID的情况相同。

When I run CI/CD command example 当我运行CI / CD命令示例时

dotnet publish -c Release -r win10-x86 -o ..\publish

I believe it creates a self-contained deployment. 我相信它创建了一个自包含的部署。 As my publish directory goes from being 55MB to 120MB and from 237 files to 482 files. 我的发布目录从55MB变为120MB,从237个文件变为482个文件。

Update 2 更新2

I have tried specifying my startup project for the publish step and it builds the run time directories to be more compact. 我已经尝试为发布步骤指定我的启动项目,并且它将运行时目录构建得更紧凑。

Here is the build command I am running: 这是我正在运行的构建命令:

dotnet publish .\startupProject.csproj -c Release -o ..\publish

And this is the output: 这是输出:

- publish/runtimes/
   - unix/
   - win/

Some of the projects in my solution do specify netstandard2.0 and some specify netcoreapp2.0. 我的解决方案中的一些项目确实指定了netstandard2.0,一些指定了netcoreapp2.0。 Does Microsoft document anywhere that if you don't specify a target framework or a specific csproj file, it will give you all of the target frameworks for all of the possible runtimes? Microsoft是否记录了如果您未指定目标框架或特定csproj文件的任何地方,它将为您提供所有可能的运行时的所有目标框架?

You should be able to specify your runtime with the dotnet publish -r switch. 您应该能够使用dotnet publish -r开关指定运行时。 From the .NET Core RID Catalog - Windows RIDs the Windows 10 / Windows Server 2016 RIDs are: .NET Core RID目录 - Windows RIDs Windows 10 / Windows Server 2016 RID是:

  • win10-x64 win10-64
  • win10-x86 win10-86
  • win10-arm win10臂
  • win10-arm64 win10-arm64

Meaning that your CI/CD command can specify the runtime: 这意味着您的CI / CD命令可以指定运行时:

dotnet publish -c Release -r win10-x86 -o ..\publish

Alternatively a single RID can be set in the <RuntimeIdentifier> element of your project file: 或者,可以在项目文件的<RuntimeIdentifier>元素中设置单个RID:

<RuntimeIdentifier>win10-x64</RuntimeIdentifier>

Multiple RIDs can be defined as a semicolon-delimited list in the project file's <RuntimeIdentifiers> element: 可以在项目文件的<RuntimeIdentifiers>元素<RuntimeIdentifiers>多个RID定义为以分号分隔的列表:

<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何解决 *** 没有规则来制作目标 'C:/Users/KlausBgamer','core/abi.cpp.o' 需要 - how do i fix *** No rule to make target 'C:/Users/KlausBgamer', needed by 'core/abi.cpp.o' 使用MSBuild定位.NET的特定版本 - Target specific version of .NET with MSBuild 如何导出目标,然后通过ExternalProject在另一个项目中使用它? - How do I export a target, then use it in another project via ExternalProject? 如何获取当前在 Xcode 中运行的目标的名称? - How do I get the name of the target that is currently running in Xcode? 在 TeamCity 中构建特定的 .NET 核心项目时引用传递依赖项时出现问题 - Problem referencing transitive dependencies when building a specific .NET Core project in TeamCity Monorepo,Travis和Matrix构建:如何仅在更改时构建特定路径? - Monorepo, Travis and Matrix builds: How do I build a specific path only when it changes? 如何使用自定义目标“ PublishToFileSystem”从发布中排除APP_DATA目录 - How to exclude APP_DATA directory from publishing using custom target “PublishToFileSystem” 如何让Cargo执行构建脚本并同时使用特定于目标的链接器? - How can I make Cargo execute a build script and use a target-specific linker at the same time? 如何在gnu make中使用目标特定变量 - how to use target specific variable in gnu make MSBuild:我需要目标重建吗? - MSBuild: Do I need Target Rebuild?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM