C# - code编译器,.NET和放大器; CF.NET [英] C# - Code compiler for .NET & CF.NET

查看:172
本文介绍了C# - code编译器,.NET和放大器; CF.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要与.NET和紧凑的.NET框架编制了同一个项目。

I've a same project that need to be compiled with .NET and Compact .NET Framework.

  1. 可以创建一个C# 编译器编译我的 项目既框架?
  2. 有些功能并不present在 CF.NET框架,所以我创造了它由 本人(产生具有类 完全相同的名称和放大器;选项 在.NET框架。如果我德科雷这 班级就像一个属性 [CF35]这是可能的解析 项目:

  1. It is possible to create a C# compiler that will compile my project with both framework ?
  2. Some feature aren't present in CF.NET Framework so I created it by myself (creating classes having exactly the same name & options that in .NET Framework. If I decore this classes with an attribute like [CF35] it's possible to parse the project and :

  • 使用这个类时,编译 使用CF.NET项目
  • 忽略这个类在使用编译项目 .NET
  • Use this class when compile the project using CF.NET
  • Ignore this class when compile the project using .NET

感谢所有建设性的答案。

Thanks for all constructive answers.

我知道,包括创建两个项目引用相同的文件解决方案。 问题是,你应该每次都手动编译两者。 此外,当您将文件添加到一个,你需要打开第二和引用它太,这只是borring做,根据我们许多人工作在同一个项目,我想自动执行此操作的一部分。

I know the solution that consists to create two projects referencing the same files. Problem is, you should every time compile both manually. Moreover, when you add a file to one, you need to open the second and reference it too, that it's just borring to do and according that we are many people to work on the same project, I would like to do this part automatically.

似乎是可能的吗?

所有工作正常,只是......资源文件!

All works fine except ... resources files !

因此​​,要恢复,我有三期工程:

So, to resume, I've three project :

  • 在开发项目(CF.NET)
  • 发行项目(CF.NET 3.5),通过包括所有的文件
  • 发行项目(.NET 3.5),通过包括所有的文件

至于说,一切工作正常,但现在我的问题是使用资源文件。

As said, all works fine, but now my problem is using Resources files.

有什么方法适用于使用它?

What's the method to apply to use it?

  • 当我使用的开发项目,资源文件被正确检索
  • 当我使用其他两个项目,ResourceManager的抛出MissingManifestResourceException

你知道吗?

推荐答案

其基本思想是将与#如果编译器指令为每个版本的框架装饰你的code?

The basic idea would be to decorate your code with #if compiler directives for each framework version?

#if CFNET
// .net CF code
#else
// .net code
#endif

从这里一个你有两种选择:

From here one you have two options:

A)和自定义生成配置1项目文件

如果您想拥有一切在1的csproj文件,你需要手动修改它。由于这是一个的MSBuild文件,这更多的是一个MSBuild的问题。我想,你需要做以下的事情:

If you would like to have everything in 1 csproj file you'll need to modify it manually. Since this is a msbuild file this is more of a msbuild problem. I figure you would need to do the following things:

  1. 使用2平台的名字说了(而不是默认的任何CPU或x86)NET和CF
  2. 定义CF常数(从现在开始编辑的csproj):

  1. Use 2 platform names say "NET" and "CF" (instead of the default Any CPU or x86)
  2. Define CF constant (From now on Edit csproj):

<的PropertyGroup条件='$(平台)==CF>      < D​​efineConstants> CF< / DefineConstants>  < /的PropertyGroup>

<PropertyGroup Condition="'$(Platform)' == 'CF'"> <DefineConstants>CF</DefineConstants> </PropertyGroup>

根据选择的平台上导入正确的构建目标:

Import correct build targets depending on selected platform:

&LT;进口条件='$(平台)==net的项目=$(MSBuildToolsPath)\ Microsoft.CSharp.targets/&GT;  &LT;进口条件='$(平台)==CF项目=$(MSBuildToolsPath)\&LT; CFtargets&GT; .targets/&GT;

<Import Condition="'$(Platform)' == 'NET'" Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Condition="'$(Platform)' == 'CF'" Project="$(MSBuildToolsPath)\<CFtargets>.targets" />

我不知道目标文件CF的名字,因为我没有安装它。前人的精力它在某处C:\ WINDOWS \ Microsoft.NET \ **目标

I don't know the targets file name of CF since I don't have it installed. It sould be somewhere in C:\Windows\Microsoft.NET\**.targets

B)2项目文件每个包含相应的生成配置

正如我一开始所指出的,也有一些评论者指出,最好的解决办法是有2个项目文件,你保持同步。你可以在这两个项目中的文件相同的源文件。

As I initially pointed out, and also some commenter pointed out, the best solution is to have 2 project files, that you keep in sync. You can have the same source files in both project files.

因此​​,一个想法是(而不是手动每次文件列表复制)到

So an idea would be (instead of copying the file list manually each time) to

  1. 在考虑使用T4模板,保留源文件同步(与有2个解决方案,这样你就不会被提示每次都重新加载整个解决方案),或者
  2. 修改这两个的csproj文件,并使用的通配符编译标记是这样的:

&LT;编译包括=** / * CS。/&GT;

这篇关于C# - code编译器,.NET和放大器; CF.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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