根据项目配置更改 csproj OutputType
我需要根据项目的配置将 C# 项目构建为 WinExe 或 Library。
我尝试过这两种方法,但没有成功:
1)在常规 PropertyGroup 中:
2) 在条件 PropertyGroup 中:
这些方法都不起作用,并且 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 .csproj 文件的顶部,您将有两个看起来有点像这样的部分:
将
OutputType
元素添加到这两个条件PropertyGroup
部分,并确保删除所有其他OutputType
元素 - 我刚刚测试过它,它完全符合您的要求。是的,这与您已经完成的非常相似,但我知道上述方法是有效的,因为我刚刚尝试过 - 我唯一的猜测是您构建中的其他地方正在搞砸事情。
In the top of your .csproj file you will have two sections that look a bit like this:
Add your
OutputType
elements to these two conditionalPropertyGroup
sections and make sure that you remove all otherOutputType
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.