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

查看:102
本文介绍了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\4.5.16\build\netcoreapp2.0AppDynamics.Agent.Windows.targets中定义.

The related build target is named as CreateAppDynamicsConfigFiles, defined in AppDynamics.Agent.Windows.targets in path: appdynamics.agent.windows\4.5.16\build\netcoreapp2.0.

此静默还原没有没有日志,因为此目标在构建之前运行.因此,普通的VS输出窗口(显示构建日志,裸包日志...)无法为其提供任何日志.(此外,作者在创建软件包时也未定义自定义方式在该目标中写入日志)

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.如果愿意修改已安装的软件包,则可以通过修改目标临时来禁用该行为.(添加

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天全站免登陆