我可以得到“有时是便携式的"产品吗?类库项目要在Visual Studio Express中加载? [英] Can I get a "sometimes portable" class library project to load in Visual Studio Express?

查看:76
本文介绍了我可以得到“有时是便携式的"产品吗?类库项目要在Visual Studio Express中加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Noda Time 1.1版,主要目标是构建可移植类库样式,主要用于支持Windows Phone和Windows Store应用程序.这意味着失去一些功能,因此我们构建了桌面配置和PCL配置(针对调试,发布和签名发布"中的每一个).

为避免必须使用多个项目文件,所有6种配置都存在于同一项目文件中. 项目文件是自定义生成的一个名为可移植性"的属性,该属性设置为"PCL"或桌面",如下所示:

<!-- Set the custom Portability property based on configuration -->
<PropertyGroup>
  <Portability Condition="'$(Configuration)' == 'Debug Portable'">PCL</Portability>
  <Portability Condition="'$(Configuration)' == 'Release Portable'">PCL</Portability>
  <Portability Condition="'$(Configuration)' == 'Signed Release Portable'">PCL</Portability>
  <!-- Default to desktop if not explicitly set above -->
  <Portability Condition="'$(Portability)' == ''">Desktop</Portability>
</PropertyGroup>

然后,根据上述属性,我们将便携式和台式机分别具有不同的属性组.这就是将项目类型定义为类库"或便携式类库"的方式(以及共享的LibraryOutputType):

<!-- Desktop-specific properties -->
<PropertyGroup Condition="'$(Portability)' == 'Desktop'">
  <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  <TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>

<!-- PCL-specific properties -->
<PropertyGroup Condition="'$(Portability)' == 'PCL'">
  <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
  <ProjectGuid>{c78f6992-28d7-45c9-a4c1-6eaa649f3247}</ProjectGuid>
  <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  <TargetFrameworkProfile>Profile2</TargetFrameworkProfile>
  <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>

这通常效果很好-我具有不同的解决方案配置,因此我可以立即构建和测试所有内容,并且只需要将每个新的.cs文件添加到单个项目文件中即可.因此,在Visual Studio 2012 Professional(我使用的是Visual Studio 2012 Professional)下,我非常高兴.

当我尝试在Visual Studio Express(VS2010或VS2012)中加载解决方案时,问题就来了.在加载解决方案时,它失败并显示一条错误消息,指出某些项目无法加载,并且两个构建PCL版本的项目都具有如下构建输出:

C:\Path\To\NodaTime.csproj : error  :
     The project file 'C:\Path\To\NodaTime.csproj' cannot be opened.

There is a missing project subtype.
     Subtype: '{786C830F-07A1-408B-BD7F-6EE04809D6DB}'
     is unsupported by this installation.

(为清晰起见,已重新格式化.)这两个项目拒绝加载,因此您甚至无法浏览源代码.

我真的希望即使Express用户无法构建PCL版本,他们仍然能够加载解决方案,浏览源代码以及构建非PCL版本. MSBuild可从命令行运行,但这并不友好.

我尝试删除引用PCL项目配置的解决方案配置,但这无济于事.奇怪的是,甚至注释掉了XML元素,像这样:

<!-- 
    <ProjectTypeGuids>(Guids as before)</ProjectTypeGuids>
 -->

没有帮助-尽管删除该行可以.好像Visual Studio并未将其实际加载为真实的XML文件一样. (我没有尝试将带有注释元素的版本加载到VS Pro中.)

可以按照需要生成单独的PCL项目文件,但是如果可能的话,我真的很想避免这样做,这会使正常的开发工作更加痛苦.同样,我可以生成仅Express的PCL和解决方案文件,但我还是不愿意-只是感觉不对.

理想情况下,我想同时支持VS Express 2010和2012,如果有仅适用于2012的解决方案,那将是一个好的开始.

所以,有什么方法可以说服Visual Studio Express,尽管有条件属性组(不满足其条件)引用了不支持的项目类型,但它确实可以 加载项目知道吗?

解决方案

大卫·基恩(David Kean)的评论给了我我现在正在使用的答案:

或完全删除< ProjectTypeGuid>元素-这会让您选择便携式"增强功能,例如用于更改目标框架的UI等

我已经尝试过了,它的工作就像一个梦.在已正确安装所有组件的计算机上,您甚至可以在Express下构建PCL版本!我已经验证了生成的二进制文件确实是PCL,而且看起来还不错.

后来发现遇到一些问题,我不会感到惊讶,但是就目前而言,这对我来说很好.在没有Visual Studio增强功能的情况下,我可以轻松地生活-我的项目已经使它们的构建配置非常不同,这已经使我感到困惑,所以我认为我并没有从中获得太多好处.

For Noda Time version 1.1, the main goal is to build a Portable Class Library flavour, primarily to support Windows Phone and Windows Store apps. This means losing some functionality, so we build a desktop configuration and a PCL configuration (for each of debug, release, and "signed release").

To avoid having to work with umpteen project files, all of the 6 configurations exist in the same project file. The project file is customized to generate a property called "Portability", which is set to either "PCL" or "Desktop", like this:

<!-- Set the custom Portability property based on configuration -->
<PropertyGroup>
  <Portability Condition="'$(Configuration)' == 'Debug Portable'">PCL</Portability>
  <Portability Condition="'$(Configuration)' == 'Release Portable'">PCL</Portability>
  <Portability Condition="'$(Configuration)' == 'Signed Release Portable'">PCL</Portability>
  <!-- Default to desktop if not explicitly set above -->
  <Portability Condition="'$(Portability)' == ''">Desktop</Portability>
</PropertyGroup>

We then have separate property groups for portable vs desktop, based on the above property. This is what defines the project type as "class library" or "portable class library" (along with the OutputType of Library, which is shared):

<!-- Desktop-specific properties -->
<PropertyGroup Condition="'$(Portability)' == 'Desktop'">
  <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  <TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>

<!-- PCL-specific properties -->
<PropertyGroup Condition="'$(Portability)' == 'PCL'">
  <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
  <ProjectGuid>{c78f6992-28d7-45c9-a4c1-6eaa649f3247}</ProjectGuid>
  <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  <TargetFrameworkProfile>Profile2</TargetFrameworkProfile>
  <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>

This generally works very well - I have the different solution configurations, so I can build and test everything at a moment's notice, and I only need to add each new .cs file to a single project file. So under Visual Studio 2012 Professional (which is what I use) I'm perfectly happy.

The problem comes when I try to load the solution in Visual Studio Express (either VS2010 or VS2012). While the solution is loading, it fails with an error to say that some projects can't be loaded, and the two projects which build PCL versions then have build output like this:

C:\Path\To\NodaTime.csproj : error  :
     The project file 'C:\Path\To\NodaTime.csproj' cannot be opened.

There is a missing project subtype.
     Subtype: '{786C830F-07A1-408B-BD7F-6EE04809D6DB}'
     is unsupported by this installation.

(Reformatted for clarity.) The two projects refuse to load, so you can't even browse the source code.

I had really hoped that even if Express users couldn't build the PCL versions, they'd still be able to load up the solution, browse the source, and build non-PCL versions. MSBuild works from the command line, but that's not as friendly.

I've tried removing the solution configurations which refer to the PCL project configurations, and that doesn't help. Weirdly enough, even commenting out the XML element, like this:

<!-- 
    <ProjectTypeGuids>(Guids as before)</ProjectTypeGuids>
 -->

doesn't help - although deleting the line does. It's as if Visual Studio isn't actually loading it as a real XML file. (I haven't tried loading the version with the commented out element into VS Pro.)

I could go down the route of generating separate PCL project files if I need to, but I'd really like to avoid it if possible - it would make normal development more painful. Likewise I could generate Express-only PCL and solution files, but again I'd rather not - it just feels wrong.

While ideally I'd like to support VS Express both 2010 and 2012, if there's a solution which only works for 2012, that would be a good start.

So, is there any way of persuading Visual Studio Express that it really can load a project despite a conditional property group (whose condition isn't met) referring to a project type it doesn't know about?

解决方案

David Kean's comment here gave me the answer I'm using for the moment:

or remove the <ProjectTypeGuid> element entirely - this will opt you of "portable" enhancements, such as a UI for changing the target framework, etc

I've tried that, and it works like a dream. On machines which have everything appropriately installed, you can then even build the PCL version under Express! I've verified that the resulting binary really is a PCL, and it seems fine.

I wouldn't be surprised to find that I ran into some problems later on, but for the moment this works fine for me. I can easily live without the enhancements in Visual Studio - it was already confused by my project having very different build configurations, so I don't think I was getting much benefit anyway.

这篇关于我可以得到“有时是便携式的"产品吗?类库项目要在Visual Studio Express中加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆