Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Add tye.yml VS Solution Items on init #568

Closed
wants to merge 9 commits into from
Closed

Add tye.yml VS Solution Items on init #568

wants to merge 9 commits into from

Conversation

spboyer
Copy link
Contributor

@spboyer spboyer commented Jun 30, 2020

Closes #372

  • Adds tye.y[a]ml file to sln files for VS users.
  • NoOps if there are no sln files
  • if multiple sln files are found assumes the first

@tebeco
Copy link
Contributor

tebeco commented Jun 30, 2020

When doing dotnet build|run|... it fails if there's multiple match

From a developer point of view "First sln match" is

  • not always going to be the expected one
  • tampering with unwanted sln

I understand that it should not "fail", maybe a warning while still creating tye.yaml ?
I have no real good idea, just curious about editing a file without very clear "rule" or way to make sure this is what was intended by the user

we did not edited any solution file as ... multiple sln founds

@jkotalik
Copy link
Contributor

jkotalik commented Jul 9, 2020

Agree with @tebeco here, I think we should not add it to any slns when multiple.

src/tye/InitHost.cs Outdated Show resolved Hide resolved
Agreed.Accepting change here.

Co-authored-by: Justin Kotalik <[email protected]>
@spboyer spboyer requested a review from jkotalik July 9, 2020 19:30
Copy link

@JunTaoLuo JunTaoLuo left a comment

Choose a reason for hiding this comment

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

Manually editing a sln file seems quite error prone. What kind of testing has been done to verify this PR?

Ideally we would use a library like Microsoft.DotNet.Cli.Sln.Internal which is available on this feed. The problem here is that the TFMs are incompatible but I'm curious if we can update the TFM of the tool to net5.0 @jkotalik ?

// assume the first one is the one wanted.
var sln = slnFiles[0];
//format
var insertItem = @$"Project(""{fileGuid}\"") = ""Solution Items"", ""Solution Items"", ""{fileGuid}""

Choose a reason for hiding this comment

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

A few things here:

  1. Why is there a backslash \ after fileGuid? Looks like that's not needed since you already have "" which should resolve correctly to a quotation mark.
  2. How did you come up with this format for insert Item? Specifically, from my understanding of this doc the two Guids should not be the same, one is a project Guid, one is a project type Guid. The current logic creates a random Guid and uses it for both, which doesn't seem right. Have you tested this logic? What does the sln file look like after you open it?
  3. This logic assumes it's safe to insert a folder called Solution Items, what if that folder already exists in the sln file?

Choose a reason for hiding this comment

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

I tested it out and it seems like adding this section worked:

+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D85F58E9-CD8F-45D7-B2F2-ADAE5812E9C0}"
+       ProjectSection(SolutionItems) = preProject
+               tye.yaml = tye.yaml
+       EndProjectSection
+EndProject

Still needs logic to resolve whether Solution Items already exists in the sln file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @JunTaoLuo for the comments here. The \ was a miss on the last edit, will fix this and I'll make a quick change to check for the existing "Solution Items".

Copy link

@JunTaoLuo JunTaoLuo left a comment

Choose a reason for hiding this comment

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

How are you verifying this change? I think if you opened the sln file, there will be a load error.


lines.ForEach(l =>
{
if (l.IndexOf("(SolutionItems)") > 0)

Choose a reason for hiding this comment

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

This logic doesn't work, (SolutionItems) may be specified in other itemgroups. For example in gRPC projects, often protobuf files are included as solution items under Proto directory e.g. here, this logic will add tye.yaml to that directory which wouldn't make any sense. You'll need to look for a project with the name Solution Items.

{
var fileGuid = Guid.NewGuid().ToString("B").ToUpper();

insertItem = @$"Project(""{fileGuid}"") = ""Solution Items"", ""Solution Items"", ""{fileGuid}""

Choose a reason for hiding this comment

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

No this is still wrong, the two Guids have different purposes and should not be the same. Again, how are you verifying this change? I think if you opened the sln file, there will be a load error.

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 SolutionItems is a good call out here. Testing process has been using the simple microservices.sln example from the docs. Opening the sln in VS works fine. There is no loading error.

Ideally, there should be dotnet sln add functionality in the dotnet CLI to support this beyond **proj files.

Choose a reason for hiding this comment

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

When I test this locally, I see
image

It's because the project type Guid is invalid if you just use a randomly generated Guid.

Choose a reason for hiding this comment

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

And I agree, maybe file an issue here https://github.com/dotnet/sdk/issues for dotnet sln to have the ability to add solution file? Also this is why I mentioned that it would be better to use the Microsoft.DotNet.Cli.Sln.Internal library if we plan to update our TFM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved the Guid issue. There is a section Guid, project references should have the same in the first and then an identifier for the second. Solution items are their own section. Taking a dependency on on dotnet cli commands would be preferred over Microsoft.DotNet.Cli.Sln.Internal in the future.

Added issue :dotnet/sdk#12454

@spboyer spboyer closed this Jul 14, 2020
@spboyer
Copy link
Contributor Author

spboyer commented Jul 14, 2020

Closing for now. This is getting messy and not providing value, might revisit.

Also found old backlog item for adding sln non-project items in CLI - dotnet/sdk#9611 @JunTaoLuo

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

Successfully merging this pull request may close these issues.

Should we add tye.yaml as a solution item when running tye init
4 participants