[英]Changing csproj OutputType based on project configuration
I need to build a C# project as either WinExe or Library depending on the project's configuration. 我需要根据项目的配置将C#项目构建为WinExe或Library。
I've tried both of these methods with no luck: 我试过这两种方法都没有运气:
1) In the general PropertyGroup: 1)在一般PropertyGroup中:
<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType> <OutputType Condition=" '$(Configuration)' == 'Debug' ">Library</OutputType>
2) In a conditional PropertyGroup: 2)在条件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. 这两种方法都不起作用,OutputType始终是WinExe。 The odd thing is that if I change all instances of WinExe to Library, then it's always Library.
奇怪的是,如果我将WinExe的所有实例更改为库,那么它总是库。 This is making me think that it is reading them successfully, but either in a strange order or that WinExe takes precedence over Library.
这让我觉得它正在成功地阅读它们,但要么是以奇怪的顺序,要么WinExe优先于图书馆。
Any ideas? 有任何想法吗?
In the top of your .csproj file you will have two sections that look a bit like this: 在.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>
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. 将
OutputType
元素添加到这两个条件PropertyGroup
部分,并确保删除所有其他OutputType
元素 - 我刚刚测试它,它完全符合您的要求。
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. 是的,这与你已经完成的非常相似,但我知道上述方法有效,因为我刚刚尝试过 - 我唯一的猜测就是你构建中的其他地方的东西搞乱了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.