How to set the path to the resource file relative to the project file?

Say I have a directory A, and in this directory there is a project file x.csproj and sln. I also have an x.resources resource file in it.

How to install a resource file without an absolute path C:\A\x.resources , but a relative path .\x.resources ? I tried with x.resources , but it does not work.

enter image description here

+4
source share
3 answers

Just ran into the same problem. My colleague did not even try to fix this in the user interface, but simply hacked the CSPROJ file in a text editor:

CSPROJ path : C: \ foo \ bar \ SolutionNm \ ProjectNm \ ProjectNm.csproj

File Path : C: \ foo \ bar \ Icons.res

Original:

  <PropertyGroup> <Win32Resource>C:\foo\bar\Icons.res</Win32Resource> </PropertyGroup> 

Modified:

  <PropertyGroup> <Win32Resource>..\..\Icons.res</Win32Resource> </PropertyGroup> 

If you have not yet tried to change the value in the user interface, it will not complain

Cheers, Aaron

+6
source

I understand that the crawler used .NET, but just like FYI, for C ++ projects you have to edit your VCXPROJ file and the resources are stored in a slightly different format at the bottom of the file.

Original:

 <ItemGroup> <Image Include="C:\projects\dragdroptree\DragDropView\res\bmp00001.bmp" /> <Image Include="C:\projects\dragdroptree\DragDropView\res\toolbar1.bmp" /> </ItemGroup> 

Modified:

 <ItemGroup> <Image Include="res\toolbar.bmp" /> <Image Include="res\bmp00001.bmp" /> </ItemGroup> 

Just to clarify, the paths you insert refer to the directory where the VCXPROJ file is located.

+1
source

NOTE Visual Studio sometimes puts the <PropertyGroup> <Win32Resource> too early in .csproj, so you need to manually edit the XML and move the <PropertyGroup> after the <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> element to link will relate to the .csproj file.

0
source

All Articles