[英]VS 2015: WPF Project Template with Nuget-Packages
我正在嘗試創建一個帶有 ResourceDictionary、一個窗口和一些 NuGet 包的小型 WPF 模板項目。 我找到了這本手冊: https : //shahbhavya47.wordpress.com/2015/03/11/create-visual-studio-project-template-with-pre-installed-nuget-packages-using-vs-sdk/
它工作得很好,但是一旦我添加了 WPF-UserControls,我就會得到一些奇怪的行為:
我在這件事上做錯了什么,還是有一些指南圍繞 WPF 模板以及如何使用它們?
提前致謝!
馬蒂亞斯
這是我如何讓它工作的步驟:
<OutputType>
更改為WinExe ,將<RequiredFrameworkVerison>
更改為 4.0<PropertyGroup>
,以便 VS 可以將項目識別為 WPF 應用程序。<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<ItemGroup>
添加到.csproj文件以確保文件在從模板生成的項目中正確標記: <ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ProjectItem>
元素添加到.vstemplate文件中: <ProjectItem ReplaceParameters="true" TargetFileName="App.xaml">App.xaml</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainWindow.xaml">MainWindow.xaml</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="App.xaml.cs">App.xaml.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainWindow.xaml.cs">MainWindow.xaml.cs</ProjectItem>
ReplaceParameters="true"
可以將文本標記包含到 4 個添加的文件中的任何一個中。 我在 App.xaml.cs 中使用了$safeprojectname$
:
public partial class App : Application
{
private string field = "$safeprojectname$";
}
在 MainWindow.xaml 中:
<Grid>
<TextBlock>$safeprojectname$</TextBlock>
</Grid>
在此之后,構建模板項目在 bin/Debug 文件夾中生成了 zip 文件,該文件按預期工作,包括替換兩個文件中的那些$safeprojectname$
實例。
請記住,模板項目的主要目標是構建模板,因此,例如,從該項目打開.xaml文件將在設計器中顯示無效標記。 從普通 WPF 項目開始,然后將其文件和.csproj文件的相關部分復制到模板項目中要容易得多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.