We have a solution with a shared project that is referenced by two other projects.
In the shared project, we have resx
files, but we noticed the code-behind Designer.cs
file is not updated when adding or modifying terms in the resx. Apparently, custom tool generation (ResXFileCodeGenerator) for embedded resources is not supported in shared projects.
I have been searching quite a while to overcome this limitation. I tried creating a class library with all resource files but then I stumbled on the problem that I cannot add a reference to that class library in the shared project.
Does anyone have any idea how I could fix this? Having resource files in a class library, and being able to use them in our shared project views?
--
Apart from the problem above, we can get the resx
files working on the projects when we just add the code ourselves in the Designer.cs
file, but still it looks like there are still some issues.
For example, in the view, we can get the translations through our namespace and the term name, but in the IDE they are shown as red (not resolvable). However, if we run the application, it works like it should.
UPDATE: I was able to have translations from a resx
file in a separate project shown in my views when running the application. However, in the shared project, where the views reside, my references to the resx
file are still displayed in red. This is probably because the shared projects has no references to the translation project. Once built, the 'real' projects which have a reference, can find the resx
translations so no problem when running the application.
Is there any way to tell visual studio that my shared project uses resx
files from a separate class library, so that it finds the terms and doesn't underline my references? It would be nice to have the intellisense working.
As requested in the comments, see a snippet of my View/Html code:
@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> @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> @CategoryResources.SPIS_Categories_Maintenance.Label_No</button>
</div>
</div>
</div>
</div>
And then see this screenshot, where the references aren't recognized:
Notice also, that the ViewBag is also not recognized. But when running, all works as expected...
A resource file is a text file with the extension . rc. The file can use single-byte, double-byte, or Unicode characters. The syntax and semantics for the RC preprocessor are similar to those of the Microsoft C/C++ compiler. However, RC supports a subset of the preprocessor directives, defines, and pragmas in a script.
Shared Projects allows sharing code, assets, and resources across multiple project types. More specifically, the following project types can reference and consume shared projects: Console, Windows Forms, and Windows Presentation Foundation. Windows Store 8.1 apps and Windows Phone 8.1 apps.
What is a Shared Project? The concept of shared projects were introduced in Visual Studio 2013 RC 2, and in a nutshell, allow you to reference an entire project as opposed to just a single assembly like you would with a class library.
Visual Studio provides a resource editor that lets you add, delete, and modify resources. At compile time, the resource file is automatically converted to a binary . resources file and embedded in an application assembly or satellite assembly. For more information, see the Resource files in Visual Studio section.
This is working for me using Visual Studio 2015, try the following:
Don't name your shared resources "Resources.resx" or "Resource.resx" as this can lead to conflicts. Use something like "Strings.resx" or "Translation.resx".
Make sure the access modifier is public when you open the resx file in the designer:
Could be just a namespace issue in the design view. Include the namespace for the resources in the Views/web.config
file. The Views will use the namespaces included there to resolve types.
Views/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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With