How to add existing item to Visual Studio project, copy to output but change it's original name?

不想你离开。 提交于 2019-12-12 03:26:34

问题


I added a chm help file as link to the application's project but it's file name is not good for releasing to the public ("Compiled help.chm"). Unfortunately it's maintained in a different git submodule by other people and it's name is an automated output from their help builder.

After adding file as link there is no option to change the file name. Is there a csproj xml feature allowing user to rename a file link, possibly without breaking WiX installers depending on it and other undesired consequences?


回答1:


I was a bit curious about this one, so I gave it a try myself, and I think I was able to get something that will work for you:

  1. If you have the file already in your project as a link, skip to 2; o/w, drag the file over your project in Visual Studio and - while holding down both Ctrl and Shift - drop the file on your project, creating a link.
  2. Close the solution and project
  3. Using notepad or some other text editor, edit the .csproj file, then locate your logical link by looking for the filename you just added.
  4. Edit the link node as follows:
<ItemGroup>
    <None Include="....\OtherTeamOutputFolder\Compiled help.chm">
        <Link>Super Cool Production Product Name.chm</Link>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
</ItemGroup>
  1. Build your project; witness the glory.



回答2:


If you control WiX project, you can specify file name in the file element:

<Component…>
  <File Id=”FILE_MyProgramDir_SomeAssemblyDLL”
    Name=”SomeNewNameForAssembly.dll”
    Source=”SomeAssembly.dll”
    KeyPath=”yes” />
</Component>

However, you should consider the new name while accessing to renamed resources both from your executable/class libraries and from other stuff.



来源:https://stackoverflow.com/questions/28188872/how-to-add-existing-item-to-visual-studio-project-copy-to-output-but-change-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!