根据项目的配置更改的csproj输出类型 [英] Changing csproj OutputType based on project configuration
问题描述
我需要建立为根据项目的配置无论是WinExe或图书馆C#项目
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)在一般的PropertyGroup:
1) In the general PropertyGroup:
<输出类型条件='$(配置)'=='释放'> WinExe< /输出类型>
<输出类型条件='$(配置)'=='调试'>图书馆< /输出类型>
2)在有条件的PropertyGroup:
2) In a conditional PropertyGroup:
<的PropertyGroup条件='$(配置)'=='释放'>
<输出类型> WinExe< /输出类型>
< /的PropertyGroup>
<的PropertyGroup条件='$(配置)'= ='调试'>
<输出类型>图书馆与LT; /输出类型>
< /&的PropertyGroup GT;
这些方法都不工作,在输出类型总是WinExe。奇怪的是,如果我改变WinExe的所有实例库,那么它总是库。这使我认为这是成功地阅读它们,但无论是在陌生的顺序或WinExe接管图书馆优先。
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.
任何想法?
推荐答案
在您的.csproj的顶部文件,你将有两个部分,看上去有点像这样:
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>
添加您的输出类型
元素,这两个条件的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.
这篇关于根据项目的配置更改的csproj输出类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!