Transforming .csproj using nuget package

我是研究僧i 提交于 2020-01-01 05:29:05

问题


I know it is possible to transform source code files and config files using a custom Nuget package. Unfortunately I cannot find anywhere on how to be able to append to or change a .csproj file. Is this possible?


回答1:


The only file modifications that are directly supported in NuGet without resorting to PowerShell are:

  • web.config and app.config transforms.

You can add files from your NuGet package into the project, but they will overwrite the existing files. The files added can also be transformed if they are .pp files.

Note that there is a move away from PowerShell scripts in NuGet 3 so you may want to see if you get away with not using PowerShell. Other alternatives are custom MSBuild .props and .targets files you can include in your NuGet package which can be used to indirectly modify the project files. You can basically add anything you want to the existing project in your own custom MSBuild .targets file since this is imported into the project.

PowerShell scripts can be used to append or change a .csproj. There are some example NuGet packages that do this, such as the older Bcl Build NuGet package which adds an import element to the project. Note that adding an import is directly supported in the latest NuGet.

Transforming existing code files with PowerShell is more difficult but you can modify code files using the Visual Studio object model.



来源:https://stackoverflow.com/questions/35017029/transforming-csproj-using-nuget-package

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