Shared projects and resource files

We have a solution with a joint project referenced by two other projects.

In the general project, we have resx files, but we noticed that the code-behind Designer.cs file does not update when conditions are added or changed in resx. Apparently, creating custom tools (ResXFileCodeGenerator) for embedded resources is not supported in shared projects.

I have been looking for quite some time to overcome this limitation. I tried to create a class library with all resource files, but then I came across a problem that I can not add a link to this class library in the general project.

Does anyone know how I can fix this? The presence of resource files in the class library and the possibility of their use in our common design concepts?

-

Besides the problem described above, we can get resx files working on projects when we just add the code to the Designer.cs file, but still it looks like there are still some problems.

For example, in a view, we can get translations through our namespace and name, but in the IDE they appear as red (not resolvable). However, if we run the application, it works as it should.

UPDATE: I was able to get translations from the resx file into a separate project, which is shown in my views when the application starts. However, in the general project where the views are located, my links to the resx file resx still displayed in red. This is probably due to the fact that common projects do not have references to the translation project. After creating "real" projects that have a link, they can find resx translations, so no problem starting the application.

Is there a way to tell visual studio that my shared project uses resx files from a separate class library so that it finds terms and does not underline my links? It would be nice to work with intellisense.


As pointed out in the comments, see 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>&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> 

And then look at this screenshot where the links are not recognized:

No links found

Please also note that the ViewBag is also not recognized. But at startup, everything works as expected ...

+7
c # visual-studio asp.net-mvc shared-project
source share
2 answers

It may just be a namespace problem in the design view. Include the namespace for the resources in the Views/web.config . Views will use the namespaces included there for type resolution.

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> 
+2
source share

This works for me using Visual Studio 2015, try the following:

  • Do not 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 constructor:

Resource Access Modifier

  1. Add a link to your project and specify the namespace in your /web.config view, as described in @Nkosi's answer.
+2
source share

All Articles