简体   繁体   English

使用Nuget包更新AssemblyInfo.cs

[英]Update AssemblyInfo.cs with Nuget package

Is it possible to update AssemblyInfo.cs file with nuget? 可以使用nuget更新AssemblyInfo.cs文件吗?

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. 目前我唯一能想到的解决方案是使用Install.ps1并在那里播放内容,但这可能很麻烦。 Is there any more elegant solution? 还有更优雅的解决方案吗?

During the installation of a nuget package you cannot modify existing files unless you use the powershell script. 在安装nuget软件包期间,除非使用powershell脚本,否则无法修改现有文件。 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. 某些软件包的根目录中有一个readme.txt及其说明,这可能是一种向开发人员提供说明的方法,因为它会在安装软件包后打开。

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. 到目前为止,没有其他方法可以使用in项目在类中更新/添加条目。 To perform custom operation the Install.ps1 and Uninstall.ps1 files were introduced. 为了执行自定义操作,引入了Install.ps1和Uninstall.ps1文件。 The powershell script is passed with objects of EnvDTE to perform the operations with the files of a project/solutions. Powershell脚本与EnvDTE的对象一起传递,以对项目/解决方案的文件执行操作。

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. 尽管示例作者尝试将XMLConfigurator插入Main或Application_Start()方法中。 you can customize the following part to edit the AssemblyInfo.cs instead of Program.cs 您可以自定义以下部分以编辑AssemblyInfo.cs而不是Program.cs

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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