简体   繁体   English

将目标框架从v4.0更改为v3.5后,找不到命名空间

[英]Namespace cannot be found after changing target framework from v4.0 to v3.5

I have 2 projects in a solution, 1 a dll, the other an exe. 我在解决方案中有2个项目,1个dll,另一个是exe。 Both were using .net version 4.0 however no 4.0 specific libraries were used so it should be possible for me to safely change them to 3.5 两者都使用.net 4.0版,但没有使用4.0特定的库,所以我应该可以安全地将它们更改为3.5

I did this under both project properties, I built the dll fine. 我在两个项目属性下做了这个,我建立了dll罚款。 Now when i try to build the exe it cannot find the dll's namespace. 现在,当我尝试构建exe时,它无法找到dll的命名空间。 I have readded the reference, but it still cant see it. 我已经读过参考文献,但它仍然无法看到它。 When I reverted the .net version it did say I might have to modify the project files before it builds. 当我恢复.net版本时,它确实说我可能必须在构建之前修改项目文件。 I have tried to search for a solution via google but the key words I am using are too commonly used. 我试图通过谷歌搜索解决方案,但我使用的关键词太常用了。 Can anyone advise? 任何人都可以建议吗?

Many thanks, Chris 非常感谢,克里斯

Edit: Tried the following already.. 编辑:尝试了以下..

  • Reference DLL specifically whilst ensuring not 4.0 copy 具体参考DLL,同时确保不是4.0副本
  • Delete bin and obj folders 删除bin和obj文件夹
  • Restart VS 重启VS.

Rather than referencing the output DLL, have you tried setting it as a project reference instead. 您尝试将其设置为项目引用,而不是引用输出DLL。

Also, have you done a clean build of the solution incase any .Net 4.0 files were lingering? 此外,你有没有完成解决方案的任何.Net 4.0文件挥之不去? You can manually clean the project by deleting the bin and obj folders. 您可以通过删除bin和obj文件夹来手动清理项目。

Have you tried removing the projects from the solution, creating a new .net 3.5 project and compiling that. 您是否尝试从解决方案中删除项目,创建一个新的.net 3.5项目并进行编译。 Then add in the ddl project (Add -> existing project) and compile, then add in exe project without reference, compile then add in the references. 然后在ddl项目中添加(添加 - >现有项目)并编译,然后在没有引用的情况下添加exe项目,编译然后在引用中添加。

Odd question, but have you check the name spaces still. 奇怪的问题,但你还检查名称空间。 Can you call in your project the namesapce, ie using mydllproject.model.myengine 你可以在你的项目中调用namesapce,即using mydllproject.model.myengine

I would open your project files as XML. 我会将您的项目文件打开为XML。 To do this, close the soltion and reopen the projects only by clicking the down arrow on the File/Open button and selecting Open With... XML (Text) Editor. 要执行此操作,请关闭soltion并仅通过单击“文件/打开”按钮上的向下箭头并选择“打开方式... XML(文本)编辑器”重新打开项目。 Check to make sure each project has a ToolsVersion="4.0" in the header. 检查以确保每个项目的标题中都有ToolsVersion =“4.0”。 Check the RootNamespace and TargetFrameworksVersion elements to see if they have the values that you expect. 检查RootNamespace和TargetFrameworksVersion元素以查看它们是否具有您期望的值。 At the bottom of the file, check the ProjectReference element within the ItemGroup. 在文件的底部,检查ItemGroup中的ProjectReference元素。 Make sure the GUID in the project reference matches the GUID that is defined in your solution file. 确保项目引用中的GUID与解决方案文件中定义的GUID相匹配。

Finally, make sure you clean your project before you rebuild it. 最后,确保在重建项目之前清理项目。 If you're using source control, check out the project into a new, empty sandbox. 如果您正在使用源代码管理,请将项目签入新的空沙箱。

Good Luck! 祝好运!

I had a very similar problem to this. 我有一个非常类似的问题。 In my case it I had two projects, a 'class library' and a windows forms application in the same solution. 就我而言,我在同一个解决方案中有两个项目,一个“类库”和一个Windows窗体应用程序。

After changing the target framework of both the projects to .NET4.0 framework, and adding a reference to the class library in my windows forms application, it wouldn't detect the namespace of my class library. 在将两个项目的目标框架更改为.NET4.0框架,并在我的Windows窗体应用程序中添加对类库的引用之后,它将不会检测我的类库的命名空间。

Here is what I did that finally solved the problem: 以下是我所做的,最终解决了这个问题:

  1. Created a new project with .NET 4.0 framework as the target framework. 使用.NET 4.0框架作为目标框架创建了一个新项目。 I imported all my forms and classes into this project from the original solution. 我从原始解决方案中将所有表单和类导入到此项目中。

  2. Added the existing class library as a new project. 将现有类库添加为新项目。

  3. Added a reference to the class library project from my windows forms project 从我的Windows窗体项目添加了对类库项目的引用

  4. For each of the class files under the class library project, I set the 'Build Action' to 'Compile' 对于类库项目下的每个类文件,我将“Build Action”设置为“Compile”

  5. Right-clicked the class library project and selected to 'Rebuild'. 右键单击类库项目并选择“重建”。

  6. Then when I go into my windows forms projects, I can see the namespace when I use the ' using namespace_name ' statement. 然后,当我进入我的Windows窗体项目时,我可以在使用' using namespace_name '语句时看到命名空间

Note: Maybe you do not need to create a new project like I did in the first few steps. 注意:也许您不需要像我在前几个步骤中那样创建新项目。 But changing the Build Action definitely did the trick. 但是改变Build Action肯定是有用的。

Hope it helps. 希望能帮助到你。

-Put dll and exe in 3.5 -Put dll和exe在3.5
-Compile the dll only - 仅编译dll
-Delete the reference to the dll and readd it - 删除对dll的引用并读取它
-Rebuild the solution - 重建解决方案

Check the DLLs that you are referencing what kind of target runtime they require, especially the "Engine.dll". 检查引用它们所需的目标运行时类型的DLL,尤其是“Engine.dll”。 You could do this with the .NET Refractor for example. 例如,您可以使用.NET Refractor执行此操作。 If they are compiled for v4.0, then yuou need to get versions for an earlier version of .NET runtime. 如果它们是为v4.0编译的,那么你需要获得早期版本的.NET运行时版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Framework从v3.5迁移到v4.0 - NET Framework migration from v3.5 to v4.0 如何在Windows 8中处理.Net Framework版本V4.0和V3.5 - How to deal with .Net framework versions V4.0 vs V3.5 in Windows 8 从源文件编译程序时,如何将目标框架设置为v2.0或v3.5而不是4.0? - How to set the target framework to v2.0 or v3.5 instead of 4.0 when compiling a program from a source file? 无法在多个项目上更改目标框架从v4.0到V4.5或4.5.1 - Cannot change Target Framework on Several Projects From v4.0 to V4.5 or 4.5.1 调试时,托管旧版(v3.5,v3.0,v2.0)和托管旧版(v4.5,v4.0)的默认设置在哪里? - Where is the default setting for Managed Legacy (v3.5, v3.0, v2.0) vs Managed Legacy (v4.5, v4.0) when debugging? 使用4.6v dll而不将当前项目目标框架从v4.0升级到v4.6 C# - Using 4.6v dll without upgrading current project target framework from v4.0 to v4.6 C# 将项目的.NET目标框架从4.0更改为3.5后,找不到文件(或程序集) - File (or assembly) can't be found after changing project's .NET target-framework from 4.0 to 3.5 如何在没有.NET v4.0的目标环境上部署.NET v4.0应用程序? - How can I deploy .NET v4.0 application on target environment without .NET v4.0? Visual Studio 2010:无法解析目标框架“.NETFramework,Version=v4.0”的 mscorlib - Visual Studio 2010: Could not resolve mscorlib for target framework '.NETFramework,Version=v4.0' 如何使用.Net框架v3.5调用异步任务 - How to call async Task using the .Net framework v3.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM