基于目标框架的有条件附录frameworktoOutputpath

发布于 2025-02-13 21:32:35 字数 1251 浏览 3 评论 0原文

我正在尝试为大量项目设置appendTargetFrameWorkToOutputPath,但取决于目标帧。

因此,我基本上必须

<PropertyGroup Condition="'$(TargetFramework)'=='net48'">
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>

并且必须弄清楚它的位置,因此我不必在所有项目中复制代码。

到目前为止,我已经弄清楚了:

directory.build.props:如果我不指定条件(centerion =“'$(targetFramework)'=='net48''< /code>)它可靠地起作用。如果我仅将其限制为特定的目标帧,则仅在项目多目标时才有效。即&lt; targetFrameWorks&gt; net48; net5.0&lt;/targetFrameWorks&gt;效果很好,但对于&lt; targetFramework&gt; net48&lt;/targetFramework&gt; not -code> the条件> forse -frome -false -code the条件 - 令人惊讶的是,由于构建。 CSPROJ(考虑到这一点的实现,多目标也不足为奇)。

directory.build.targets:虽然这将解决问题框架未在CSPROJ中设置的问题,但似乎在评估过程中为时已晚,并且已经设置了输出路径。

除了要求所有项目都使用&lt; targetFrameworks&gt;外,还有什么方法? (这将是一个非常脆弱的解决方案)。

请注意,这不是重复的CSPROJ可以使您对定义的导入何时可以更好地控制。

I'm trying to set AppendTargetFrameworkToOutputPath for a large number of projects, but depending on the TargetFramework.

So basically I have

<PropertyGroup Condition="'$(TargetFramework)'=='net48'">
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>

and have to figure out where to put it so I don't have to duplicate code in all projects.

What I've figured out so far:

Directory.Build.props: If I don't specify a condition (Condition="'$(TargetFramework)'=='net48'") it works reliably. If I limit it to only a specific TargetFramework then it only works if the project is multi-targeting. I.e. <TargetFrameworks>net48;net5.0</TargetFrameworks> works fine, but for <TargetFramework>net48</TargetFramework> the condition evaluates to false - not too surprising since the Build.props file is evaluated before the TargetFramework is set in the csproj (also not too surprising that multi-targeting works, given how this is implemented).

Directory.Build.targets: While this would solve the problem with the TargetFramework not being set in the csproj, it seems like this is too late in the evaluation process and the output path is already set.

Is there any way around this apart from requiring all projects to use <TargetFrameworks>? (which would be an incredibly fragile solution).

Note that this is NOT a duplicate, since the user is importing the common file manually in the csproj which gives you much finer control over when the definitions are imported.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2025-02-20 21:32:35

您可以使用&lt; beforetargetFrameworkInferenceTargets&gt;属性来指定在构建过程中正确时间执行的目标文件的路径。

You can use the <BeforeTargetFrameworkInferenceTargets> property to specify the path to a target file that is executed at the right time during the build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文