简体   繁体   中英

Update AssemblyInfo.cs with Nuget package

Is it possible to update AssemblyInfo.cs file with nuget?

The only solution that crossing my mind at the moment is to use Install.ps1 and to play around with content there, but that can be messy. Is there any more elegant solution?

During the installation of a nuget package you cannot modify existing files unless you use the powershell script. Messing with existing content of files might easily break whatever is in the file. (Personal note: I would be extremely annoyed)

You can add files but you should be careful with that because those files might get replaced when the developer upgrades the package.

Some packages have a readme.txt in their root with instructions, that might be a way to give instructions to the developer as it will open after installing the package.

Providing good documentation and refraining from messing with other files or adding a lot of files to a solution might be the friendliest way.

There's no other way till now to update/add an entry in the a class with in project. To perform custom operation the Install.ps1 and Uninstall.ps1 files were introduced. The powershell script is passed with objects of EnvDTE to perform the operations with the files of a project/solutions.

You can take a look at this sample reference . Though the sample author is trying to insert the XMLConfigurator in either Main or Application_Start() method. you can customize the following part to edit the AssemblyInfo.cs instead of Program.cs

param($installPath, $toolsPath, $package, $project)
// ==> Change
$item = $project.ProjectItems.Item("AssemblyInfo.cs")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM