简体   繁体   English

根据项目配置更改csproj OutputType

[英]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.

相关问题 运行outputType库项目 - Run outputType library project VS 2015不断更改CSPROJ项目文件中的TargetOfficeVersion - VS 2015 keeps changing TargetOfficeVersion in CSPROJ project file Nuget 恢复仅在项目 OutputType 为 exe 时有效 - Nuget restore only works if project OutputType is exe 为csproj禁用发布配置 - Publish Configuration disabled for csproj MSBuild:如何根据构建源项目的名称有条件地在.csproj文件中导入另一个项目? - MSBuild: How to conditionally import another project in a .csproj file based on the name of build-originated project? TeamCity更改csproj文件中的提示路径 - TeamCity changing the hintpath in csproj files .NET Core:如何在project.json旁边使用基于csproj的项目? - .NET Core: How to use csproj-based projects alongside project.json? 尝试包装基于 .csproj 的项目以从 asp net 5 库中使用时,dnu 包装“无法解析引用” - dnu wrap "Failed to resolve references" when trying to wrap .csproj based project for use from asp net 5 library 如何将数据传递给 csproj,或者我可以在 C# .netFramework 项目中的新构建配置上使用#if 指令 - How can I pass data to csproj or can I use #if directive on a new build configuration in C# .netFramework project .CSProj文件中没有项目类型向导 - No project Type Guid in .CSProj file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM