【发布时间】:2018-12-31 20:20:53
【问题描述】:
我正在创建一个文件生成器,它还会将添加的文件添加到更改的,而不是当前项目的 csproj 文件中,以便自动包含。
所有文件(如 cs 文件)都可以正常工作,但是,我不明白如何使用此 API 为构建创建一个子级。
目前,我的代码将文件添加到构建中,但 xaml cs 和 xaml 已连接但在视觉上是分开的(xaml cs 文件不在 xaml 文件内)
我的代码如下:(input.FolerPath是解决路径)
public void Execute(GeneratorInput input)
{
var p = new Microsoft.Build.Evaluation.Project(input.FolderPath + ".csproj");
p.AddItem("Compile", "SomePath.cs"); // this works given a proper path
p.AddItem("Compile", "XamlCsPath.xaml.cs"); // this works for the xaml cs
p.AddItem("Page", "XamlPath.xaml"); // this creates the xaml file seperately
}
最终,我想要实现的是以下csproj文件:
<Compile Include="XamlCsFile.xaml.cs"> // I got this far
<DependentUpon>XamlFile.xaml</DependentUpon> // this is what I am trying to add
</Compile>
【问题讨论】:
-
我想这就是你要找的东西:stackoverflow.com/a/44160484/8507673
-
envDTE 操作当前的 csproj。我的应用程序修改了当前未打开的远程 csproj
标签: c# wpf xaml csproj addchild