共享项目和资源文件

Ver*_*osa 8 c# asp.net-mvc visual-studio shared-project

我们有一个共享项目的解决方案,该项目由另外两个项目引用.

在共享项目中,我们有resx文件,但我们注意到Designer.cs在resx中添加或修改术语时不会更新代码隐藏文件.显然,共享项目不支持嵌入式资源的自定义工具生成(ResXFileCodeGenerator).

我一直在寻找克服这个限制的一段时间.我尝试使用所有资源文件创建一个类库,但后来我偶然发现了无法在共享项目中添加对该类库的引用的问题.

有谁知道如何解决这个问题?将资源文件放在类库中,并且能够在我们的共享项目视图中使用它们吗?

-

除了上面的问题,resx当我们只是在Designer.cs文件中添加代码时,我们可以获取文件上的文件,但看起来仍然存在一些问题.

例如,在视图中,我们可以通过命名空间和术语名称获得翻译,但在IDE中,它们显示为红色(不可解析).但是,如果我们运行应用程序,它的工作方式应该如此.

更新:resx在运行应用程序时,我能够在我的视图中显示的单独项目中的文件中进行翻译.但是,在视图所在的共享项目中,我对该resx文件的引用仍以红色显示.这可能是因为共享项目没有引用翻译项目.一旦构建,具有引用的"真实"项目可以找到resx翻译,因此在运行应用程序时没有问题.

有没有办法告诉visual studio我的共享项目使用resx来自单独的类库的文件,以便它找到条款并且不强调我的引用?让intellisense工作会很好.


根据评论中的要求,请参阅我的View/Html代码片段:

@using System.Configuration
@{
    ViewBag.Title = "ManageCategories";
}
<div class="main container-fluid">
<div id="spis-categories" ng-controller="categoriesController as categoriesVm" ng-cloak ng-init="categoriesVm.siteName='@ConfigurationManager.AppSettings["siteName"]';categoriesVm.pageSize = @inConnexion.Common.Constants.Constants.PageSize">
<div class="modal cust-modal-ontop" tabindex="-1" role="dialog" id="confirmDeleteDialog" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog cust-modal-dialog">
        <div class="modal-content cust-modal-content">
            <div class="modal-header">
                <h4 class="modal-title">@CategoryResources.SPIS_Categories_Maintenance.Button_Delete</h4>
            </div>
            <div class="modal-body">
                <p>@CategoryResources.SPIS_Categories_Maintenance.Confirm_Delete</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" ng-click="categoriesVm.doDeleteSelected();"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>&nbsp;@CategoryResources.SPIS_Categories_Maintenance.Label_Yes</button>
                <button type="button" class="btn btn-default" ng-click="categoriesVm.cancelDeleteSelected();"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>&nbsp;@CategoryResources.SPIS_Categories_Maintenance.Label_No</button>
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

然后查看此屏幕截图,其中无法识别引用:

没有找到参考

另请注意,ViewBag也无法识别.但是在跑步时,一切都按预期工作......

Nko*_*osi 2

可能只是设计视图中的命名空间问题。在文件中包含资源的命名空间Views/web.config。视图将使用其中包含的名称空间来解析类型。

视图/web.config

<pages pageBaseType="System.Web.Mvc.WebViewPage">
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing" />
    <add namespace="System.Net.Http" />
    <add namespace="{Resources name space here}" />
    <!-- You could also include System.Configuration to avoid having to use using -->
    <add namespace="System.Configuration" />
  </namespaces>
</pages>
Run Code Online (Sandbox Code Playgroud)