I have a GUI project that is supported by a class library. Both belong to the same solution and serve a similar purpose so I would like to give them the same name. This should be possible since the file name for the GUI application would be foo.exe
and foo.dll
for the library. However, attempting this in practice causes the CLR to be unable to find one of the assemblies.
我有一个由类库支持的GUI项目。两者都属于相同的解决方案,并提供类似的目的,所以我想给他们相同的名称。这应该是可能的,因为GUI应用程序的文件名将是库的foo.exe和foo.dll。但是,在实践中尝试此操作会导致CLR无法找到其中一个程序集。
At first, part of the problem seems to be that the PDB file name is generated from the assembly name and not the file name, e.g. the PDB is named foo.pdb
instead of foo.exe.pdb
. Therefore one PDB overwrites the other. However, even in Release mode where a PDB is not needed, the assembly still fails to execute with the same exception, so perhaps the problem has nothing to do with debugging at all.
首先,部分问题似乎是PDB文件名是从程序集名称而不是文件名生成的,例如, PDB名为foo.pdb而不是foo.exe.pdb。因此,一个PDB会覆盖另一个PDB。但是,即使在不需要PDB的Release模式下,程序集仍然无法以相同的异常执行,因此问题根本与调试无关。
How can I create a solution that contains an application (exe) and class library (dll) with the same name?
如何创建包含具有相同名称的应用程序(exe)和类库(dll)的解决方案?
2 个解决方案
#1
3
This is not possible. The CLR locates assemblies by their display name. The display name for both your EXE and your DLL project is "foo", it does not include a filename extension. Accordingly, when the CLR needs to find the assembly "foo", it will first try "foo.EXE" and next "foo.DLL". Clearly this will not work well in your case, your program will bomb when it tries to use a type from the class library.
这不可能。 CLR按其显示名称定位程序集。 EXE和DLL项目的显示名称是“foo”,它不包含文件扩展名。因此,当CLR需要找到程序集“foo”时,它将首先尝试“foo.EXE”和下一个“foo.DLL”。很明显,这在你的情况下效果不好,你的程序会在尝试使用类库中的类型时炸弹。
You must use a different name.
您必须使用其他名称。
#2
0
If having the same name is all you care about, then this is what I would suggest. I'm going to start from scratch here if you don't mind:
如果您关心的是同一个名字,那么这就是我的建议。如果你不介意,我将从头开始
- Create a blank solution.
- 创建一个空白解决方案
- Add two new solution folders, "App" and "Library".
- 添加两个新的解决方案文件夹,“App”和“Library”。
- Open Windows Explorer, go to your solution directory and create 2 directories with the same names, "App" and "Library"
- 打开Windows资源管理器,转到解决方案目录并创建两个名称相同的目录,“App”和“Library”
- Go back to Visual Studio, add your GUI project under "App". Let's call it "foo". Make sure you put it under your "App" directory you created in step 3.
- 返回Visual Studio,在“App”下添加GUI项目。我们称之为“foo”。确保将其放在您在步骤3中创建的“App”目录下。
- Likewise, do the same thing for your library project, put it under "Library". Call it "foo" and make sure it goes into "Library" directory.
- 同样,为您的图书馆项目做同样的事情,把它放在“图书馆”下。称之为“foo”并确保它进入“Library”目录。
- You should be able to compile it now.
- 你现在应该可以编译了。
#1
3
This is not possible. The CLR locates assemblies by their display name. The display name for both your EXE and your DLL project is "foo", it does not include a filename extension. Accordingly, when the CLR needs to find the assembly "foo", it will first try "foo.EXE" and next "foo.DLL". Clearly this will not work well in your case, your program will bomb when it tries to use a type from the class library.
这不可能。 CLR按其显示名称定位程序集。 EXE和DLL项目的显示名称是“foo”,它不包含文件扩展名。因此,当CLR需要找到程序集“foo”时,它将首先尝试“foo.EXE”和下一个“foo.DLL”。很明显,这在你的情况下效果不好,你的程序会在尝试使用类库中的类型时炸弹。
You must use a different name.
您必须使用其他名称。
#2
0
If having the same name is all you care about, then this is what I would suggest. I'm going to start from scratch here if you don't mind:
如果您关心的是同一个名字,那么这就是我的建议。如果你不介意,我将从头开始
- Create a blank solution.
- 创建一个空白解决方案
- Add two new solution folders, "App" and "Library".
- 添加两个新的解决方案文件夹,“App”和“Library”。
- Open Windows Explorer, go to your solution directory and create 2 directories with the same names, "App" and "Library"
- 打开Windows资源管理器,转到解决方案目录并创建两个名称相同的目录,“App”和“Library”
- Go back to Visual Studio, add your GUI project under "App". Let's call it "foo". Make sure you put it under your "App" directory you created in step 3.
- 返回Visual Studio,在“App”下添加GUI项目。我们称之为“foo”。确保将其放在您在步骤3中创建的“App”目录下。
- Likewise, do the same thing for your library project, put it under "Library". Call it "foo" and make sure it goes into "Library" directory.
- 同样,为您的图书馆项目做同样的事情,把它放在“图书馆”下。称之为“foo”并确保它进入“Library”目录。
- You should be able to compile it now.
- 你现在应该可以编译了。