I have a resx file in the App_GlobalResources folder of my ASP.NET web application.
Its build property must be set to "Content", so that the file is automatically included during publishing and I can use <%$ Resources: ... %>
expressions.
Its build property must be set to "Embedded Resource", so that my unit tests can access the resources.
Is there some trick that I can use to have both?
Note: The solutions in the linked question won't work, since
<%$ Resources: ... %>
support after deployment.Is there any solution that I have missed?
Set the build property of your resource files to "Embedded Resource".
Then, to ensure that they are included when publishing, add the following to the bottom of your vbproj
or csproj
file:
<Target Name="CopyResx" AfterTargets="CopyAllFilesToSingleFolderForPackage">
<ItemGroup>
<ResxFilesToCopy Include="App_GlobalResources\*.resx" />
</ItemGroup>
<Copy SourceFiles="@(ResxFilesToCopy)" DestinationFolder="$(WebProjectOutputDir)\$(WPPAllFilesInSingleFolder)\App_GlobalResources" />
</Target>
Note: We need to use CopyAllFilesToSingleFolderForPackage
instead of MSDeployPublish
, since the latter won't be executed when publishing a web application to a file system directory.