Bug 53270 - TargetFrameworkVersion Automatically updating Projects when opened
Summary: TargetFrameworkVersion Automatically updating Projects when opened
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: 4.3.1 (15.1)
Hardware: PC Windows
: --- enhancement
Target Milestone: 15.4
Assignee: Bugzilla
: 45073 ()
Depends on:
Reported: 2017-03-12 21:13 UTC by David Strickland
Modified: 2017-07-21 14:44 UTC (History)
7 users (show)

Is this bug a regression?: No
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David Strickland 2017-03-12 21:13:33 UTC
Currently if you open a project that has 

Is immediantly updated in the proj.

This update can not be undone or reverted because every time you try it just changes it back. This means if your unfortunate enough to Open Such a Project you MUST commit this change to be allowed to change to a different branch withen the IDE.

More details 
here: https://bugzilla.xamarin.com/show_bug.cgi?id=45073

Please dont just close this as Answered.

The fact that you get stuck in a loop in the IDE is a bug and should be addressed. No other tools automagically decide to change my source code and have no option that allows me NOT to have my source code automagically changed.

 is set then
should be ignored\removed
NOT updated by a plugin whenever I happen to open old source code.
Comment 1 John Miller [MSFT] 2017-03-13 10:10:06 UTC
Hi David,

Sorry for the confusion on #45073. There were some comments from the team explaining the behavior but they were marked private. The gist of the issue is that this is happening because `AndroidUseLatestPlatformSdk` is true. When that is true, the latest `TargetFrameworkVersion` is used. If you prefer to manually specify `TargetFrameworkVersion`, set `AndroidUseLatestPlatformSdk` to false.
Comment 2 Juan Marcelo Tondato 2017-03-13 13:23:50 UTC
Hi David,

Sorry for the confusion.

The issue is because the msbuild property 'AndroidUseLatestPlatformSdk' is true.
When project is loaded in this case we are setting the latest sdk installed in your machine automatically (always use the latest).

If you want to use an specific target framework version, please set `AndroidUseLatestPlatformSdk` to false and take into account that you must change the `TargetFrameworkVersion` manually. 

Please, let me know if the fix solve your problem.
Comment 3 Juan Marcelo Tondato 2017-03-13 13:24:38 UTC
*** Bug 45073 has been marked as a duplicate of this bug. ***
Comment 4 David Strickland 2017-03-13 14:36:05 UTC
No of course that doesnt "solve" the problem.

If I open Visual Studio in the Master Branch of my Repo it immediately makes a change to the code. At my current company as well as any major company that has to live and work under any sort of legally mandated Change Management system. I do not have the rights to modify the Master branch. All changes are made to a different Branch and Merged up to Master. However the Xamarin Addon IMMEDIATELY changes the code. No option. No way to prevent it, stop it, undo it, revert it, clean it or any other way to put it. The Xamarin Addon is mandating a code change NOW on the current branch regardless of what policies or procedures such changes must be made under. I can't even get switched over to another branch to do the mandated code change and request that the PR be merged because I can't switch branches until I Commit the "changes" I've made to the branch I'm on. 

If the change was a prebuild step that would be better at least it requires some sort of user interaction. However I would argue then even a build shouldn't change source code unless it generates the entire file every time and can be excluded from source control. I can't think of any other situation where  opening a file changes the underlying source without some sort of a "Do you want to ..." dialog box. Word, Excel, Powerpoint, Graphics Apps other IDE's, other Visual Studio Addons. None of these applications make changes to the source document or files without at least prompting the user the change is going to be made. The fact that Xamarin does something no other apps do makes it annoying and none intuitive. The fact that it puts VS into a completely unusable state makes it a bug.

When these magic changes suddenly happen the only way to get past it is to exit the IDE jump out to Git Bash do a Revert and get another branch you do have rights to and reopen the IDE. If the Xamarin environment puts the Visual Studio application into a state that my only option is to Close the app and fix it then it's broken. Regardless of why it is broken, what options make it broken or what very reasonable excuse there is for breaking it and to me that qualifies this whole mess as a bug. As for what the fix it several come to mind.

Option 1. Like any other App prompt the user for permission before making changes to their documents.

Option 2. Make the two options in the proj file mutually exclusive. If one is set the other is ignored.

Option 3. Remove Both options and use a third new option that combines the 2 the same way they are combined in the Options dialog.

Option 4. Only make the change on File Load and Compile so that a Revert is possible without having to exit the IDE\Solution to do it.
Personally I'd think Option 3 is the best option but any of the above would make VS usable.
Comment 5 John Miller [MSFT] 2017-03-13 17:42:38 UTC
I'm updating this report to an enhancement request, with comment #4 being the suggestions. I'll leave it up to the VS team to decide on where the priority and target is for this. For now, I've moved it to "Future Cycle" as a TBD.
Comment 6 David Strickland 2017-03-13 17:57:21 UTC
Thanks ...

One additional Note on this that came up in our standup today. 

If you want to turn OFF AndroidUseLatestPlatformSdk but lock in on Android SDk 7.1 there is currently no way to accomplish this. 

You Can chose "Use Latest" or use an old version there is no way to Chose what is currently the latest(7.1) without also turning AndroidUseLatestPlatformSdk to true.

So even if we wanted to turn off this "Feature" there is no way to do it short of N++.
Comment 7 Joaquin Jares 2017-07-20 16:03:21 UTC
Hi David,

The problem is that TargetFrameworkVersion is required by other components (particularly Nuget), so we have to always have it. AndroidUseLatestPlatformSdk is something we use to make devs lives easier, but we _need_ to change TargetFrameworkVersion to make everything work. Come VS components expects that property to exist in the csproj. I understand this is an absolute nuisance. I'll check with nuget to see if that was resolved recently (I really don't think so, it's mostly by design).

On your latest comment, you should be able to set any sdk that you have installed in the computer, so there's something going on there. Also, if UseLatest is changing your version that implies that the latest available sdk (installed in the devs computers) is different for different people in your team? The easiest, really, is to have everyone have the same latest installed on their machines. If that doesn't work, then there's something we need to be looking into.
Comment 8 David Strickland 2017-07-21 04:52:54 UTC
Thanks for the follow up. I should have updated this. a patch a couple months ago fixed the issue that wouldn't let you select the newest version without selecting "latest". The fact that it auto changes the file and theres is no way to "exclude" that change from source control remains a PNA but I can at least select the newest version now thanks.
Comment 9 Joaquin Jares 2017-07-21 14:44:52 UTC
Excellent that it worked. I'll close this as fixed (based on the fix you mention). Do reopen if you see anything like it again. We'll keep the conversation open internally on changing that, although it doesn't really look like we can right now.