使用Nuget包更新AssemblyInfo.cs

时间:2022-08-28 03:10:58

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. Is there any more elegant solution?

目前我想到的唯一解决方案是使用Install.ps1并在那里播放内容,但这可能很麻烦。还有更优雅的解决方案吗?

2 个解决方案

#1


1  

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.

到目前为止,没有其他方法可以在项目中更新/添加类中的条目。为了执行自定义操作,引入了Install.ps1和Uninstall.ps1文件。 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. you can customize the following part to edit the AssemblyInfo.cs instead of Program.cs

您可以查看此示例参考。虽然示例作者试图在Main或Application_Start()方法中插入XMLConfigurator。您可以自定义以下部分来编辑AssemblyInfo.cs而不是Program.cs

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

#2


1  

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)

在安装nuget软件包期间,除非使用powershell脚本,否则无法修改现有文件。弄乱现有的文件内容可能会轻易破坏文件中的任何内容。 (个人提示:我会非常生气)

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.

提供良好的文档并避免搞乱其他文件或向解决方案添加大量文件可能是最友好的方式。

#1


1  

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.

到目前为止,没有其他方法可以在项目中更新/添加类中的条目。为了执行自定义操作,引入了Install.ps1和Uninstall.ps1文件。 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. you can customize the following part to edit the AssemblyInfo.cs instead of Program.cs

您可以查看此示例参考。虽然示例作者试图在Main或Application_Start()方法中插入XMLConfigurator。您可以自定义以下部分来编辑AssemblyInfo.cs而不是Program.cs

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

#2


1  

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)

在安装nuget软件包期间,除非使用powershell脚本,否则无法修改现有文件。弄乱现有的文件内容可能会轻易破坏文件中的任何内容。 (个人提示:我会非常生气)

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.

提供良好的文档并避免搞乱其他文件或向解决方案添加大量文件可能是最友好的方式。