This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
[Ide] Consider MSBuild item conditions in Solution pad #9407
Open
mrward
wants to merge
3
commits into
main
Choose a base branch
from
conditional-project-files
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ProjectNodeBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// ProjectNodeBuilderTests.cs | ||
// | ||
// Author: | ||
// Matt Ward <[email protected]> | ||
// | ||
// Copyright (c) 2019 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using MonoDevelop.Core; | ||
using MonoDevelop.Ide.Gui.Pads.ProjectPad; | ||
using MonoDevelop.Projects; | ||
using NUnit.Framework; | ||
using UnitTests; | ||
|
||
namespace MonoDevelop.Ide.Projects | ||
{ | ||
[TestFixture] | ||
[RequireService (typeof (RootWorkspace))] | ||
class ProjectNodeBuilderTests : IdeTestBase | ||
{ | ||
[Test] | ||
public async Task ConditionalFiles () | ||
{ | ||
FilePath solutionFile = Util.GetSampleProject ("ConditionalFiles", "ConditionalFiles.sln"); | ||
|
||
using (var solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFile)) { | ||
var p = solution.GetAllProjects ().OfType<DotNetProject> ().Single (); | ||
|
||
// Debug configuration. | ||
IdeApp.Workspace.ActiveConfigurationId = "Debug"; | ||
|
||
var treeBuilder = new TestTreeBuilder (); | ||
treeBuilder.ParentDataItem [typeof (Project)] = p; | ||
|
||
var nodeBuilder = new ProjectNodeBuilder (); | ||
nodeBuilder.BuildChildNodes (treeBuilder, p); | ||
|
||
var debugFiles = treeBuilder.ChildNodes.OfType<ProjectFile> ().ToList (); | ||
var debugFileNames = debugFiles.Select (f => f.FilePath.FileName).ToList (); | ||
Assert.That (debugFileNames, Has.Member ("MyClass.cs")); | ||
Assert.That (debugFileNames, Has.Member ("MyClass-Debug.cs")); | ||
Assert.That (debugFileNames, Has.No.Member ("MyClass-Release.cs")); | ||
Assert.AreEqual (2, debugFiles.Count); | ||
|
||
// Release configuration. | ||
IdeApp.Workspace.ActiveConfigurationId = "Release"; | ||
|
||
treeBuilder.ChildNodes.Clear (); | ||
nodeBuilder.BuildChildNodes (treeBuilder, p); | ||
var releaseFiles = treeBuilder.ChildNodes.OfType<ProjectFile> ().ToList (); | ||
var releaseFileNames = releaseFiles.Select (f => f.FilePath.FileName).ToList (); | ||
Assert.That (releaseFileNames, Has.Member ("MyClass.cs")); | ||
Assert.That (releaseFileNames, Has.Member ("MyClass-Release.cs")); | ||
Assert.That (releaseFileNames, Has.No.Member ("MyClass-Debug.cs")); | ||
Assert.AreEqual (2, releaseFiles.Count); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's no way to avoid this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ToArray part? I did also try ConcurrentDictionary but that broke a test. There is some code that relies on the order of the items in the dictionary which works when using Dictionary. Using the lock was a way to make sure the test did not fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this collection to allow concurrency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing this change I ran into an InvalidOperationException
Collection was modified
being thrown when getting the properties for a project configuration (ProjectConfiguration.Properties.GetProperties ()
).Adding a new file to the project saves the project and the project configuration properties are modified. Values are added and then removed (if they are to be merged up to the parent group) when OnWriteProjectHeader is called. If that save happens at the same time as another thread accesses the project configuration properties then the InvalidOperationException can occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this InvalidOperationException is not really related to the changes you are doing, isn't it? If that's the case, it would be better to do them in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to be related as far as I can see. The change made here, to look at the MSBuild condition, makes use of the project configuration properties on the UI thread and the first time I tested adding a file it triggered the InvalidOperationException resulting in no files being displayed in a folder in the Solution pad window. The comment on the second commit has the exception callstack I ran into - 78345ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about doing this change in 8.4, since it might have an important impact in performance.