我正在尝试使用MSBuild:编译生成器在Visual Studio中保存文件时触发我的自定义文件类型的编译(应该像自定义工具一样工作,但使用msbuild)。构建过程本身正在工作,但如果文件被保存似乎没有触发。
有人可以解释MSBuild:编译条目到底在做什么吗?到目前为止,我刚刚看到它在antlr msbuild脚本和XAML中使用。
下面我有一个msbuild设置的摘录,用于将* .myext文件编译为* .g.ts文件。
我的目标文件:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="SampleNamespace.CustomCompilerTask" AssemblyFile="MyTask.dll" />
<PropertyGroup>
<PrepareResourcesDependsOn>
CustomLayoutCompile;
$(PrepareResourcesDependsOn)
</PrepareResourcesDependsOn>
</PropertyGroup>
<ItemDefinitionGroup>
<CustomTypeCompile>
<Generator>MSBuild:Compile</Generator>
</CustomTypeCompile>
</ItemDefinitionGroup>
<Target Name="CustomLayoutCompile" Inputs="@(TypeScriptCompile);@(CustomTypeCompile)" Outputs="@(CustomTypeCompile->'%(RootDir)%(Directory)%(Filename).g.ts')">
<CustomCompilerTask TypeScriptFiles="@(TypeScriptCompile)" LayoutFiles="@(CustomTypeCompile)" />
</Target>
</Project>
项目文件中的条目:
....
<ItemGroup>
<TypeScriptCompile Include="MyControl.ts">
<DependentUpon>MyControl.myext</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="MyControl.g.ts">
<DependentUpon>MyControl.myext</DependentUpon>
</TypeScriptCompile>
</ItemGroup>
<ItemGroup>
<CustomTypeCompile Include="MyControl.myext">
<Generator>MSBuild:Compile</Generator>
</CustomTypeCompile>
</ItemGroup>
....
<Import Project="path/to/my/target/file/mytargets.targets" />
....
答案 0 :(得分:0)
我正在使用 VS 2019 并且遇到了同样的问题。我终于找到了一种解决方法,这使问题对我来说更像是 VisualStudio/MSBuild 错误。我的解决方法是,当您定义 ItemDefinitionGroup
时,定义一个自定义/扩展文件属性页面,如下所示。它对我有用。希望它也适用于其他所有人。
<ItemGroup>
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)CustomPerperties.CSharp.xml">
<Context>File;BrowseObject</Context>
</PropertyPageSchema>
<AvailableItemName Include="CustomTypeCompile" />
</ItemGroup>