[英]Two C# project files for VS2010 and VS2012 in the same directory
I'm writing a C# project which I want to compile both under VS2010 and VS2012. 我正在编写一个C#项目,我想同时在VS2010和VS2012下进行编译。 I want to have two different
.csproj
files for that, even though VS2010-project can be directly included in VS2012-solution. 我想为此使用两个不同的
.csproj
文件,即使VS2010-project可以直接包含在VS2012-solution中。 I want two different project files because of different target .NET-versions. 由于目标.NET版本不同,我需要两个不同的项目文件。
Additionally, I want both projects to be named the same within different solutions for VS2010 and VS2012. 另外,我希望两个项目在VS2010和VS2012的不同解决方案中被命名为相同的名称。 The both should share the same
.cs
-files and, possibly, some resources. 两者应该共享相同
.cs
-files,可能还有一些资源。
Easy task? 简单的任务? Strange thing, but I don't know, how to do that properly.
奇怪的事情,但我不知道如何正确执行。
First approach, doesn't work: name project files as MyProject10.csproj
and MyProject12.csproj
, leave both in the MyProject
folder. 第一种方法不起作用:将项目文件命名为
MyProject10.csproj
和MyProject12.csproj
,将两者都保留在MyProject
文件夹中。 But in this case they are displayed in solution as MyProject10
and MyProject12
, not simply MyProject
. 但是在这种情况下,它们在解决方案中显示为
MyProject10
和MyProject12
,而不仅仅是MyProject
。 If I rename one to MyProject
in solution explorer, it automatically renames the corresponding project file. 如果在解决方案资源管理器中将一个重命名为
MyProject
,它将自动重命名相应的项目文件。
Second approach, works, but has drawbacks. 第二种方法可行,但有缺点。 Move project files into different subdirectories, named
VS10
and VS12
, manually change include paths in .csproj
-files, adding ..\\
as a prefix. 将项目文件移动到名为
VS10
和VS12
不同子目录中,手动更改.csproj
-files中的包含路径,并添加..\\
作为前缀。 In this case I see strange shortcut-like arrows under the icons in solution explorer. 在这种情况下,我在解决方案资源管理器的图标下看到奇怪的类似于快捷方式的箭头。
The only bad thing for the second approach is that when I add new files in the project using solution explorer, this file is placed in the VS10
subdirectory, not in the root project directory. 第二种方法的唯一坏处是,当我使用解决方案资源管理器在项目中添加新文件时,该文件位于
VS10
子目录中,而不是在根项目目录中。 But it seems like project directories for .csproj
-files are the directories containing the file by design, and I use the dark side of the force which I really don't want to do. 但是,似乎
.csproj
-files的项目目录是按设计包含文件的目录,而我使用的是我实际上不想做的事情的阴暗面。
Any better ideas? 还有更好的主意吗?
Worth giving a try is changing the name of the output assembly in both projects to one and the same. 值得一试的是将两个项目中输出程序集的名称更改为一个。 The project files are still going to be different, but the output assembly will be with same name.
项目文件仍将有所不同,但是输出程序集将具有相同的名称。 Also be carefull where is the output directory.
还要注意输出目录在哪里。 I think this way you can sovle your problem.
我认为这样可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.