简体   繁体   English

进入Roslyn构建过程

[英]Hook into the Roslyn build process

是否有可能在Visual Studio / TFS构建期间挂钩Roslyn构建过程,如果是,是否可以获得Roslyn在编译期间使用的Microsoft.CodeAnalysis.Solution / Microsoft.CodeAnalysis.Project实例?

The way I see it, Jon is pretty much right in his comment. 就我看来,乔恩的评论非常正确。 What I would suggest is to create an MSBuild task, which is your wanted hook into the build process. 我建议创建一个MSBuild任务,这是您在构建过程中想要的钩子。

Create an MSBuild project file (you've probably seen them already, it's those files that have the .targets extension). 创建一个MSBuild项目文件(您可能已经看过它们,它是那些扩展名为.targets文件)。 It looks something like this: 它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="MyNamespace.MyReferenceValidationTask" AssemblyFile="MyPath\MyNamespace.dll"/>
    <Target 
        BeforeTargets="BeforeCompile"
        Name="ValidationTarget">
        <MyNamespace.MyReferenceValidationTask
            SolutionRoot="$(SolutionDir)" />
    </Target>
</Project>

The attribute in the "MyNamespace.MyReferenceValidationTask" tag "SolutionRoot" is your property in your task. “MyNamespace.MyReferenceValidationTask”标记“SolutionRoot”中的属性是您的任务中的属性。 All the macros that are available in Visual Studio are also available here. Visual Studio中提供的所有宏也可在此处获得。 (see this post here: https://stackoverflow.com/a/1453023/978594 ) (见这篇文章: https//stackoverflow.com/a/1453023/978594

What you do inside of the task is entirely up to you. 你在任务中做的事完全取决于你。 You can, for example, load your solution file with Roslyn and thus have all the projects and their references and do your desired validation. 例如,您可以使用Roslyn加载解决方案文件,从而拥有所有项目及其参考,并进行所需的验证。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM