Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF源码包引用出错 #114

Open
Zhuangkh opened this issue Dec 8, 2021 · 5 comments
Open

WPF源码包引用出错 #114

Zhuangkh opened this issue Dec 8, 2021 · 5 comments

Comments

@Zhuangkh
Copy link
Contributor

Zhuangkh commented Dec 8, 2021

如果一个WPF控件类库打包成源码包, 被另一个项目引用时, 如果项目中没有任何xaml文件, 则引用的源码包的控件会爆The name 'InitializeComponent' does not exist in the current context. (项目已启用UseWPF ,obj中不生成.g.i.cs)

此时如果添加任意xaml窗体或控件进入项目, 则可以正常编译.(obj中有源码包的.g.i.cs文件生成)

再将添加的xaml文件删除, 哪怕obj中还是有源码包相关文件, 仍然会报错.

@Zhuangkh
Copy link
Contributor Author

Zhuangkh commented Dec 8, 2021

感觉可能有某个flag需要设置? @lindexi

@lindexi
Copy link
Member

lindexi commented Dec 9, 2021

@Zhuangkh 也是已知问题之一,原因是缺少 .g 文件,没有此 InitializeComponent 方法。我也在寻找解决方法中

@lindexi
Copy link
Member

lindexi commented Dec 9, 2021

但是 WPF 的控件作为源代码包有一些锅,例如 XAML 资源获取的方式,通过程序集方式获取将不可行等。因此我不推荐将 WPF 的控件作为源代码包发布

@Zhuangkh
Copy link
Contributor Author

Zhuangkh commented Dec 9, 2021

但是 WPF 的控件作为源代码包有一些锅,例如 XAML 资源获取的方式,通过程序集方式获取将不可行等。因此我不推荐将 WPF 的控件作为源代码包发布

实际上这种场景还是比较少的...碰巧测试到了

@Zhuangkh
Copy link
Contributor Author

Zhuangkh commented Dec 9, 2021

<Target Name="GenerateTempFile" BeforeTargets="CoreCompile" Condition="'$(_TargetAssemblyProjectName)'==''">
  <CallTarget Targets="MarkupCompilePass1" />
</Target>

@lindexi 加了个Target强制生成.g文件来临时解决这个问题, 还没做更多的案例测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants