Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

visual studio - Nuget package silently adds back deleted files to project directory not only initially, but on every solution open

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.

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. 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.

  2. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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?

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

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)

Detailed Description to help us understand the negative answers above:

See part of the content:

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

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

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')" />

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)

Suggestions:

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.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.Use your workaround(fake file)...

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...