基于目标框架的有条件附录frameworktoOutputpath
我正在尝试为大量项目设置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;
外,还有什么方法? (这将是一个非常脆弱的解决方案)。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
&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.