简体   繁体   English

如何从类库项目和预编译视图创建NuGet包?

[英]How to create NuGet package from class library projects and precompiled views?

I'm using MVC 5 on my Visual Studio 2017. My VS solution currently looks like this 我在我的Visual Studio 2017上使用MVC 5.我的VS解决方案目前看起来像这样

  • Solution
    • MVC App MVC应用程序
    • Components (class library) 组件(类库)
    • Custom view engine (class library) 自定义视图引擎(类库)

Now I have created models in Components library. 现在我在Components库中创建了模型。 These models are used in MVC app views. 这些模型用于MVC应用程序视图。 I have configured MVC App to precompile views during publishing with "Merge all outputs to a single assembly" and marked "Treat as library component". 我已经将MVC App配置为在发布期间使用“将所有输出合并到单个程序集”并标记为“视为库组件”来预编译视图。

Components project is referenced to MVC app (to use it in views). 组件项目被引用到MVC应用程序(在视图中使用它)。 Custom view engine is also referenced to MVC app (to mark (in AssemblyInfo) that this library contains custom views). 自定义视图引擎也引用MVC应用程序(标记(在AssemblyInfo中)此库包含自定义视图)。

When I publish MVC app it compile all views to a single library. 当我发布MVC应用程序时,它将所有视图编译为单个库。

But I want to create NuGet package from Components project and the views. 但我想从Components项目和视图创建NuGet包。 How can I do it? 我该怎么做? Is there any option to automate this? 有没有选择自动化这个?

While NuGet has functionality to pack a project, it uses the compiler output, not the publisher output, and automatically adds all MSBuild Content types, which might not be desired in your case (I have no idea how precompiled views work). 虽然NuGet具有打包项目的功能,但它使用编译器输出而不是发布者输出,并自动添加所有MSBuild Content类型,这在您的情况下可能是不需要的(我不知道预编译视图如何工作)。

Anyway, you can always create a .nuspec file and have it pack the output of the publish command. 无论如何,您始终可以创建.nuspec文件并让它打包发布命令的输出。 At the end of the docs page there are several complete examples of nuspec files. 在docs页面的末尾有几个完整nuspec文件示例

It's been a long time since I worked on an ASP.NET project, but my memory is that MVC only automatically detects MVC controllers and razor views from the "main" assembly. 自从我从事ASP.NET项目以来已经很长时间了,但我的记忆是MVC只能从“主”程序集中自动检测MVC控制器和剃刀视图。 If you have additional controllers or views in a project reference or a nuget package, you may need to register them. 如果项目引用或nuget包中有其他控制器或视图,则可能需要注册它们。

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

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