根据项目配置更改 csproj OutputType

发布于 2024-11-26 21:38:01 字数 719 浏览 0 评论 0原文

我需要根据项目的配置将 C# 项目构建为 WinExe 或 Library。

我尝试过这两种方法,但没有成功:

1)在常规 PropertyGroup 中:

WinExeLibrary

2) 在条件 PropertyGroup 中:

<输出类型>WinExe

<输出类型>库

这些方法都不起作用,并且 OutputType 始终为 WinExe。奇怪的是,如果我将 WinExe 的所有实例更改为 Library,那么它始终是 Library。这让我认为它正在成功读取它们,但要么以奇怪的顺序,要么 WinExe 优先于库。

有什么想法吗?

I need to build a C# project as either WinExe or Library depending on the project's configuration.

I've tried both of these methods with no luck:

1) In the general PropertyGroup:

<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType>
<OutputType Condition=" '$(Configuration)' == 'Debug' ">Library</OutputType>

2) In a conditional PropertyGroup:

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputType>WinExe</OutputType>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputType>Library</OutputType>
</PropertyGroup>

Neither of these methods work and the OutputType is always WinExe. The odd thing is that if I change all instances of WinExe to Library, then it's always Library. This is making me think that it is reading them successfully, but either in a strange order or that WinExe takes precedence over Library.

Any ideas?

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

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

发布评论

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

评论(1

终止放荡 2024-12-03 21:38:01

在 .csproj 文件的顶部,您将有两个看起来有点像这样的部分:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <OutputType>Library</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <OutputType>Exe</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>

OutputType 元素添加到这两个条件 PropertyGroup 部分,并确保删除所有其他 OutputType 元素 - 我刚刚测试过它,它完全符合您的要求。

是的,这与您已经完成的非常相似,但我知道上述方法是有效的,因为我刚刚尝试过 - 我唯一的猜测是您构建中的其他地方正在搞砸事情。

In the top of your .csproj file you will have two sections that look a bit like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <OutputType>Library</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <OutputType>Exe</OutputType>
  <!-- Other properties go here -->
</PropertyGroup>

Add your OutputType elements to these two conditional PropertyGroup sections and make sure that you remove all other OutputType elements - I've just tested it and it does exactly what you are asking for.

Yes this is very similar to what you have already done, but I know for a fact that the above method works because I've just tried it - my only guess is that something somewhere else in your build is messing things up.

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