Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property to view .user file command line arguments #8494

Closed

Conversation

ocallesp
Copy link
Contributor

@ocallesp ocallesp commented Sep 15, 2022

Fixes AB#1274456

MoveUserFileCommandArgs

Microsoft Reviewers: Open in CodeFlow

@ocallesp ocallesp force-pushed the user-file-command-line-arguments branch 5 times, most recently from c7f5b91 to d16a4f6 Compare September 15, 2022 20:42
@ocallesp ocallesp marked this pull request as ready for review September 15, 2022 20:42
@ocallesp ocallesp requested a review from a team as a code owner September 15, 2022 20:42
@ocallesp ocallesp changed the title Add property to view user file command line arguments Add property to view .user file command line arguments Sep 15, 2022
@ocallesp ocallesp force-pushed the user-file-command-line-arguments branch 3 times, most recently from 6c85bb7 to 83c06c9 Compare September 15, 2022 23:35

XmlDocument doc = new XmlDocument();

#pragma warning disable CA3075 // Insecure DTD processing in XML
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify this is safe to suppress. This may be a security concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this #pragma still in the code? If you've fixed the issue, can you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the static analysis still believes this is unsafe.

Comment on lines 39 to 42
<StringProperty Name="StartArguments"
DisplayName="ReadOnly .user file command line arguments"
Description="Deprecated. This is only visible if there are command line arguments in the .user file to pass to the executable."
ReadOnly="False">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ReadOnly="True" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in last commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be removed. I think it should be added.

Currently, this property will be editable. Yet I don't think that's what we want, is it? We want to display the value here, and allow the user to migrate the value from .user to .json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we set this ReadOnly="True", cps will mark it as read only because it thinks this is a common property.

docs/repo/property-pages/property-specification.md Outdated Show resolved Hide resolved
@ocallesp ocallesp force-pushed the user-file-command-line-arguments branch 7 times, most recently from 9d43d61 to 03f5dad Compare September 18, 2022 14:09

public Task HandleAsync(UnconfiguredProject project, IReadOnlyDictionary<string, string> editorMetadata)
{
_xmlFile = project.FullPath + UserSuffix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check with the CPS team about whether it would be better to use CPS APIs to modify the .user file, rather than doing direct XML-to-disk changes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cps apis marked this property as read only and doesn't allow to make changes to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .user file is part of the loaded project; in general we shouldn't modify directly.

Do we understand why "StartArguments" is being treated as read-only?

Copy link
Contributor

@tmeschter tmeschter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We need to understand why the property is being treated as read-only.
  2. Don't modify the .user file directly.
  3. Please add unit tests.


public Task HandleAsync(UnconfiguredProject project, IReadOnlyDictionary<string, string> editorMetadata)
{
_xmlFile = project.FullPath + UserSuffix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .user file is part of the loaded project; in general we shouldn't modify directly.

Do we understand why "StartArguments" is being treated as read-only?


private async Task CopyUserArgsToLaunchProfileAsync(UnconfiguredProject project)
{
ILaunchSettingsProvider? launchSettingsProvider = project.Services.ExportProvider.GetExportedValue<ILaunchSettingsProvider>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to do this rather than import the ILaunchSettingsProvider in a constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Among other things it would make it easier to write unit tests for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already tried importing ILaunchSettingsProvider in the constructor, but I got a lot of composition errors.

private const string UserSuffix = ".user";

private string? _xmlFile;
private List<string>? userFileCommandArgs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_userFileCommandArgs


foreach (string? commandArg in userFileCommandArgs)
{
writableLaunchSettings.ActiveProfile.CommandLineArgs += " " + commandArg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to account for:

  1. CommandLineArgs may be null.
  2. CommandLineArgs may be the empty string.


foreach (string? commandArg in userFileCommandArgs)
{
writableLaunchSettings.ActiveProfile.CommandLineArgs += " " + commandArg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is going to move the StartArguments to the command line arguments of the active profile. I see two potential problems:

  1. The user may not be editing the active profile. In that case the arguments will just seem to disappear when they click the link.
  2. StartArguments potentially affect launch/debug regardless of the launch profile, but this will move them to one specific launch profile.

I'm not sure either of those is really a problem, but we should think about those scenarios.

@ocallesp ocallesp marked this pull request as draft September 19, 2022 22:52
@ocallesp
Copy link
Contributor Author

Converting this pr to draft since there is still unclear why StartArguments is treated as read-only in cps. Perhaps there is a bug in cps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants