Nuget 包不仅在最初,而且在每个打开的解决方案上都将已删除的文件静默地添加回项目目录 [英] Nuget package silently adds back deleted files to project directory not only initially, but on every solution open

查看:12
本文介绍了Nuget 包不仅在最初,而且在每个打开的解决方案上都将已删除的文件静默地添加回项目目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个已安装的 nuget 包 https://www.nuget.org/packages/AppDynamics.Agent.Windows/ 在首次安装时将 AppDynamicsConfig.json 和 AppDynamicsAgentLog.config 添加到项目目录中.

It's an installed nuget package https://www.nuget.org/packages/AppDynamics.Agent.Windows/ that adds AppDynamicsConfig.json and AppDynamicsAgentLog.config to a project directory on the first install.

如果您删除这些文件中的任何一个,它会自动以静默方式恢复.我知道这种行为是在 nuget 包规范中明确设置的,但有几个问题:

If you delete any of those files, it will be automatically and silently restored. I understand that this behaviour is explicitly set in nuget package specs, but several questions:

  1. 如何在不更改 nuget 包本身的情况下禁用此行为?我发现的唯一方法是添加假文件,它之所以有效,是因为 nuget 规范设置为仅在文件不存在时恢复".但这只是一种变通方法,应该是正常的禁用方式.

  1. How this behaviour can be disabled without changes in nuget package itself? The only way that i've found is to add fake file, it works because nuget specs set as 'restore only if file doesn't exist'. But it's just a workaround, it should be a normal way to disable it.

它在打开解决方案的瞬间静默工作,如果解决方案打开,它也几乎立即工作.相关的 nuget/build/whatever 任务是如何命名的,以及此还原的日志在哪里显示?

It works silently on a moment of the opening solution and also works almost immediatly if solution is open. How the related nuget/build/whatever task is named and where logs for this restore is presented?

推荐答案

如何在不更改 nuget 包的情况下禁用此行为本身?我发现的唯一方法是添加假文件,它有效因为 nuget 规范设置为仅在文件不存在时恢复".但这只是一种解决方法,应该是禁用它的正常方法.

How this behaviour can be disabled without changes in nuget package itself? The only way that i've found is to add fake file, it works because nuget specs set as 'restore only if file doesn't exist'. But it's just a workaround, it should be a normal way to disable it.

答案是否定的.如果您不愿意更改该 nuget 包中的文件,则无法禁用该行为.至少目前没有正常的方法来禁用它.

The answer is negative. The behavior can't be disabled if you're not willing to change the files in that nuget package. At least for now there's no normal way to disable it.

它在打开解决方案的那一刻静默工作,也可以工作如果解决方案是开放的,几乎立即.相关的如何nuget/build/whatever 任务被命名以及此还原的日志在哪里介绍?

It works silently on a moment of the opening solution and also works almost immediatly if solution is open. How the related nuget/build/whatever task is named and where logs for this restore is presented?

相关的构建目标命名为CreateAppDynamicsConfigFiles,定义在AppDynamics.Agent.Windows.targets的路径:appdynamics.agent.windows4.5.16uild etcoreapp2.0.

The related build target is named as CreateAppDynamicsConfigFiles, defined in AppDynamics.Agent.Windows.targets in path: appdynamics.agent.windows4.5.16uild etcoreapp2.0.

并且此静默恢复没有没有日志,因为此目标在构建之前运行.所以普通的VS输出窗口(显示构建日志,nuget包日志......)不能有任何日志.(另外,作者在创建包时没有定义在该目标中写入日志的自定义方式)

And there's no logs for this silent restore, cause this target runs before the build. So normal VS output window(display the build log,nuget package log...) can't have any log for it.(Also, the author doesn't define custom way to write logs in that target when creating the package)

详细说明,帮助我们理解上述否定答案:

查看部分内容:

<Target Name="CreateAppDynamicsConfigFiles" BeforeTargets="BeforeBuild;CompileDesignTime"
        Inputs="$(AppDynamicsAgentDistribMicro)AppDynamicsAgentLog.config;$(AppDynamicsAgentDistribMicro)AppDynamicsConfig.json"
        Outputs="AppDynamicsAgentLog.config;AppDynamicsConfig.json">

此目标的 BeforeTargets=BeforeBuild;CompileDesignTime,因此此目标在 CompileDesignTime 目标之前运行.

This target's BeforeTargets=BeforeBuild;CompileDesignTime, so this target runs before the CompileDesignTime target.

此目标是 VS IDE 的特定目标.它代表我们在VS代码编辑器中开发的时间.所以对于在它之前运行的CreateAppDynamicsConfigFiles,它总是在加载解决方案或解决方案打开(可开发)时执行.

This target is a particular one for VS IDE. It represents the time when we develop in VS code editor.So for the CreateAppDynamicsConfigFiles which runs before it, it will always execute when loading the Solution or when the solution is open(available to develop).

当解决方案打开(加载)时,目标并不总是运行,让我们看看这个目标中的任务:

Not the target always run when solution is open(loaded), let's see the task in this target:

<Copy SourceFiles="$(AppDynamicsAgentDistribMicro)AppDynamicsAgentLog.config" DestinationFolder="." SkipUnchangedFiles="True" Condition="!Exists('AppDynamicsAgentLog.config')" />

所以: 当使用该包的项目打开时,VS 将始终运行目标=>如果 AppDynamicsAgentLog.config 不存在,则目标中的复制任务将运行在项目文件夹中=>出现奇怪的行为(如果解决方案是打开的,更准确地说,项目是打开的,文件会一直恢复)

So: VS will always run the target when project consuming that package is open=>the Copy task in the target will run if AppDynamicsAgentLog.config doesn't exist in Project folder=>The strange behavior occurs(If the solution is open, more accurate, the project is open, the files will always be restored)

建议:

1.如果您不想更改软件包本身,则没有正常的方法可以禁用它.在创建 nuget 包时,您可能必须联系包的作者以添加选项(一个 msbuild 属性).

1.There's no normal way to disable it if you don't want to change the package itself. You may have to contact the author of the package to add the option(a msbuild property) when creating the nuget package.

2.如果您愿意修改已安装的包,可以通过修改目标暂时禁用该行为.(添加condition=false 到该目标并对其他类似目标执行一些类似操作).如果没有必要,您还可以考虑从项目中删除该包.

2.If you're willing to modify the installed package, you can disable the behavior temporarily by modifying the target.(Add condition=false to that target and do some similar actions to other similar targets). And you can also consider removing that package from your project if it's not necessary.

3.使用您的解决方法(假文件)...

3.Use your workaround(fake file)...

希望以上所有内容都能解决您对此问题的困惑:) 如果我有任何误解,请随时纠正我!

Hope all above resolves your puzzle about this issue :) If I misunderstand anything, feel free to correct me!

这篇关于Nuget 包不仅在最初,而且在每个打开的解决方案上都将已删除的文件静默地添加回项目目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆