Guy*_*nus 7 c# msbuild csproj visual-studio
我需要根据项目的配置将C#项目构建为WinExe或Library.
我试过这两种方法都没有运气:
1)在一般PropertyGroup中:
<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType>
<OutputType Condition=" '$(Configuration)' == 'Debug' ">Library</OutputType>
2)在条件PropertyGroup中:
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputType>WinExe</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputType>Library</OutputType>
</PropertyGroup>
这两种方法都不起作用,OutputType始终是WinExe.奇怪的是,如果我将WinExe的所有实例更改为库,那么它总是库.这让我觉得它正在成功地阅读它们,但要么是以奇怪的顺序,要么WinExe优先于图书馆.
有任何想法吗?
在.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>
Run Code Online (Sandbox Code Playgroud)
将您的OutputType元素添加到这两个条件PropertyGroup部分,并确保删除所有其他OutputType元素 - 我刚刚测试它,它完全符合您的要求.
是的,这与你已经完成的非常相似,但我知道上述方法有效,因为我刚刚尝试过 - 我唯一的猜测就是你构建中的其他地方的东西搞乱了.