简体   繁体   English

Output 一个 Roslyn MSBuildWorkspace 到不同的文件夹

[英]Output a Roslyn MSBuildWorkspace to different folder

When executing执行时

mSBuildWorkspace.TryApplyChanges(solution);

Visual Studio changes the solution in place. Visual Studio 更改了解决方案。 This means that if I want to output to a different location, I need to first copy the whole solution to the requested target and only then work on it.这意味着,如果我想将 output 到不同的位置,我需要首先将整个解决方案复制到请求的目标,然后才能对其进行处理。 This is error prone as the solution might have relative path links to dependencies, which can break when moving the solution.这很容易出错,因为解决方案可能具有到依赖项的相对路径链接,在移动解决方案时可能会中断。

So is there a way to tell MSBuildWorkspace to output the changes to a different folder than the source?那么有没有办法告诉MSBuildWorkspace output 更改到与源不同的文件夹?

There's no built-in support for this.对此没有内置支持。

Option #1: Instead of instead of calling TryApplyChanges you could call Solution.GetChanges to figure out what changed compared to what was originally loaded, and then call the various methods to get the changed documents and apply the edit yourself.选项#1:代替调用 TryApplyChanges,您可以调用Solution.GetChanges来确定与最初加载的内容相比发生了哪些变化,然后调用各种方法来获取更改的文档并自己应用编辑。 This means you're on the hook to actually apply the edits -- source file edits are easy (just write the updated text) but if you care about more complicated things like project changes (adding/removing references) you don't really have a way to leverage MSBuildWorkspace's support for those sorts of things.这意味着您可以实际应用编辑 - 源文件编辑很容易(只需编写更新的文本),但如果您关心更复杂的事情,例如项目更改(添加/删除引用),您真的没有一种利用 MSBuildWorkspace 对此类事物的支持的方法。

Option #2: Roslyn's open source, so you'd have to modify MSBuildWorkspace yourself to allow such a redirection, which would let you potentially try to reuse some of the more complicated logic around project manipulation.选项 #2: Roslyn 的开源,因此您必须自己修改 MSBuildWorkspace 以允许这样的重定向,这将使您有可能尝试重用一些围绕项目操作的更复杂的逻辑。 Or you can just copy/paste the implementation of the applying, and then use Solution.GetChanges and the reused code.或者您可以复制/粘贴应用程序的实现,然后使用 Solution.GetChanges 和重用代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 NetCoreApp 中使用 Roslyn:未安装 MSBuildWorkspace - Using Roslyn in NetCoreApp: MSBuildWorkspace not installed 将Roslyn MSBuildWorkspace与Visual Studio 2013一起使用 - Use Roslyn MSBuildWorkspace with Visual Studio 2013 使用 Roslyn MSBuildWorkspace 项目 AddAnalyzerReference 不加载分析器 - Use Roslyn MSBuildWorkspace Project AddAnalyzerReference doesn't load analyzers Roslyn / MSBuildWorkspace不会在非Dev计算机上加载文档 - Roslyn / MSBuildWorkspace Does Not Load Documents on Non-Dev Computer Roslyn MsBuildWorkspace编译发出的内容不包含我的更改 - Roslyn MsBuildWorkspace compilation emit does not contain my changes Roslyn,MSBuildWorkspace.Create无法与msbuild 14或12一起使用 - Roslyn, MSBuildWorkspace.Create not working with msbuild 14 or 12 如何使用Roslyn MSBuildWorkspace找到C#项目的'obj'目录? - How to find the 'obj' directory for C# projects using Roslyn MSBuildWorkspace? 编译引用.NetStandard项目的.NetStandard项目的Roslyn,MSBuildWorkspace抛出“找不到RuntimeMetadataVersion的值”。 - Roslyn, MSBuildWorkspace compiling a .NetStandard project referencing a .NetStandard project throws “No value for RuntimeMetadataVersion found.” Roslyn bin文件夹在c:\\ bin \\ roslyn中生成 - Roslyn bin folder generated at c:\bin\roslyn 在Roslyn项目中创建新文件夹 - Creating a New Folder in a Roslyn Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM