简体   繁体   English

用本地 dll 文件替换 asp.net core NuGet 包

[英]Replace asp.net core NuGet packages with local dll files

I am trying to get rid of nuget packages and have only local dll files in the project.我试图摆脱 nuget 包,并且项目中只有本地 dll 文件。

These packages I have excluded这些包我已经排除了

<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />

So, I've built my solution and imported all the dlls in the project.所以,我已经构建了我的解决方案并导入了项目中的所有 dll。 I can compile it, but the server says:我可以编译它,但服务器说:

An unhandled exception occurred while processing the request.处理请求时发生未处理的异常。 InvalidOperationException: The view 'Index' was not found. InvalidOperationException: 未找到视图“索引”。 The following locations were searched: ...搜索了以下位置:...

But having the same with nuget makes the work fine.但是与 nuget 相同可以使工作正常。 What is an alternative to add dlls to the project?将 dll 添加到项目的替代方法是什么?

I've seen this , but in my case I have too many files with the same name when I put all the dlls in one folder (conflicts)我已经看到了这一点,但在我的情况下,当我将所有 dll 放在一个文件夹中时,我有太多同名的文件(冲突)

You can always add NUget source which is local folder from you drive and make it as default or the only source of dependencies.您始终可以添加 NUget 源,它是您驱动器中的本地文件夹,并将其设为默认或唯一的依赖源。

Here are more details Local feeds这里有更多详细信息本地提要

Replace asp.net core NuGet packages with local dll files.用本地 dll 文件替换 asp.net 核心 NuGet 包。 What is an alternative to add dlls to the project?将 dll 添加到项目的替代方法是什么? I am trying to get rid of nuget packages and have only local dll files in the project.我试图摆脱 nuget 包,并且项目中只有本地 dll 文件。

Nuget is a recommended way to manage the assemblies for your project. Nuget 是管理项目程序集的推荐方法。 When you have access to Internet, using nuget is very convenient for your situation.当您可以访问 Internet 时,使用 nuget 非常适合您的情况。

But according to your another post here, you're trying to develop/build the project in environment with no Internet.但是根据您在此处的另一篇文章,您正在尝试在没有 Internet 的环境中开发/构建项目。 If so, we can still use nuget for this situation:如果是这样,我们仍然可以在这种情况下使用 nuget:

Step1: Clear all Nuget cache in VS=>Tools=>Options=>Nuget Package Manager=>General. Step1:清除VS=>Tools=>Options=>Nuget Package Manager=>General中的所有Nuget缓存。 (All packages you once used in VS are cached in %userprofile%\\.nuget\\packages , we can easy to restore the packages using nuget store , so feel free to clear the cache) (你曾经在VS中使用过的所有包都缓存在%userprofile%\\.nuget\\packages ,我们可以使用nuget store轻松恢复包,所以请随时清除缓存)

Step2: Delete the bin and obj folders of your current web project, and then restore packages for only your current project.( nuget restore , dotnet restore or simply rebuild the project in VS,VS will restore the packages for you) Step2:删除你当前web项目的bin and obj文件夹,然后只恢复你当前项目的包。( nuget restore , dotnet restore或者干脆在VS中重建项目,VS会为你恢复包)

Step3: Now let's navigate to the %userprofile%\\.nuget\\packages folder, now every packages in packages folder is that your current project depends on.第三步:现在让我们浏览到%userprofile%\\.nuget\\packages文件夹,现在在每个包packages文件夹是当前项目依赖。 Let's rename the folder name from packages to mypackages .让我们将文件夹名称从packages重命名为mypackages Now all the packages(assemblies) your project need are in mypackages folder.现在您的项目需要的所有包(组件)都在mypackages文件夹中。

Step4: We can then copy/move this folder into your project folder. Step4:然后我们可以将此文件夹复制/移动到您的项目文件夹中。 We can add this folder into source control or what depending on your actual needs.我们可以将此文件夹添加到源代码管理中或根据您的实际需要添加什么。 You can feel free to deploy your project to another server(no-internet) and continue on your work.您可以随意将您的项目部署到另一台服务器(无互联网)并继续您的工作。

As to how to reference them, you can fetch the assemblies you need from mypackages folder and manually reference them.(Add=>Reference=>...).至于如何引用它们,您可以从mypackages文件夹中获取您需要的程序集并手动引用它们。(添加=>引用=>...)。 Or use this better way with nuget, add the path where your mypackages folder exist to Package Source , you can restore the packages for your project easily even in no-Internet environment.或者将这种更好的方式与 nuget 一起使用,将mypackages文件夹所在的路径添加到Package Source ,即使在没有 Internet 的环境中,您也可以轻松地为您的项目恢复包。

Hope it helps and feel free to let me know if you need any further info or support :)希望它有所帮助,如果您需要任何进一步的信息或支持,请随时告诉我:)

Probably missing a reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation .可能缺少对Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation的引用。 You can add a dll for this package and then compile the Project or solution.您可以为此包添加 dll,然后编译项目或解决方案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM