-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use AdhocWorkspace instead of MSBuildWorkspace (#1987)
* update Versions.props to preview 8. * Use Document.Name for filepath Co-authored-by: deepchoudhery <decho@microsoft.com>
- Loading branch information
1 parent
ef571b9
commit f2c6b26
Showing
4 changed files
with
29 additions
and
15 deletions.
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
12 changes: 6 additions & 6 deletions
12
src/Shared/Microsoft.DotNet.Scaffolding.Shared/CodeModifier/CodeAnalysisHelper.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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.MSBuild; | ||
using System.IO; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Microsoft.DotNet.Scaffolding.Shared.CodeModifier | ||
{ | ||
//static class helper for CodeAnalysis | ||
public static class CodeAnalysisHelper | ||
{ | ||
//helps create a CodeAnalysis.Project with project files given a project path. | ||
public static async Task<CodeAnalysis.Project> LoadCodeAnalysisProjectAsync( | ||
public static CodeAnalysis.Project LoadCodeAnalysisProject( | ||
string projectFilePath, | ||
IEnumerable<string> files) | ||
{ | ||
var workspace = MSBuildWorkspace.Create(); | ||
var project = await workspace.OpenProjectAsync(projectFilePath); | ||
var workspace = new AdhocWorkspace(); | ||
var project = workspace.AddProject(Path.GetFileName(projectFilePath), "C#"); | ||
var projectWithFiles = project.WithAllSourceFiles(files); | ||
project = projectWithFiles ?? project; | ||
return project; | ||
} | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
test/Shared/Microsoft.DotNet.Scaffolding.Shared.Tests/CodeAnalysisHelperTests.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,18 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.DotNet.Scaffolding.Shared.CodeModifier; | ||
using Xunit; | ||
|
||
namespace Microsoft.DotNet.Scaffolding.Shared.Tests | ||
{ | ||
public class CodeAnalysisHelperTests | ||
{ | ||
[Fact] | ||
public void LoadCodeAnalysisProjectTest() | ||
{ | ||
var files = new List<string>(); | ||
var projectPath = string.Empty; // TODO test project | ||
var project = CodeAnalysisHelper.LoadCodeAnalysisProject(projectPath, files); | ||
Assert.NotNull(project); | ||
} | ||
} | ||
} |