Shared projects are crazy useful when developing for multiple platforms. Some people choose Portable Class Libraries (PCL), but if you need platform specific code, shared projects is the way to go.
Too long to read? Check out the animated gif on how to fix the issue.
Recently I was porting Orchestra and all Orc packages to support NET 4.5 besides NET 4.0. To do this, I introduce a shared project and create a NET40 and NET45 project that references the shared project. An example can be seen in the image below:
This works great because I only have to add files to the shared project, and the files will be compiled for both NET40 and NET45.
However, after converting my projects to shared projects, the WPF resources no longer worked. After digging into this issue, I found out that they don’t work very well with shared projects. As you can see in the image taking with .NET reflector below, it does not embed the resources correctly.
By default it uses the Content build action. Changing that to Resource manually via the properties window doesn’t work:
The next thing I tried was manually changing the item inside projitems (the shared project file).
<Resource Include="$(MSBuildThisFileDirectory)Resources\Images\sharedproject_resource.png" />
This excludes the file from the projitems (no longer supported), but it does embed it as resource. Unfortunately the path is lost:
The solution is to use linked files for this. The following steps should be taken:
- Exclude the resources from the shared project (don’t delete them, just exclude them)
- Enable the Show all files toggle in the solution explorer
- Hold the Alt key and drag the resources to each project.
- Ensure that the build action of the resources is Resource
You can also check out the animated gif at the beginning of this post for a visual presentation of the fix.
Issue on MS Connect
Want this fixed? Please vote here on Microsoft Connect: