I've created a WPF application using the new CSPROJ format in Visual Studio 2017.
By
- setting the LanguageTargets,
- setting the generator for XAML files,
- setting the build action for App.Xaml,
- and forcing the debug executable
I can successfully build and run the application. However, I have an issue in that the code editor does not recognize any controls placed in the XAML, so I get erroneous errors and no intellisense in the editor.
Steps to reproduce
- Launch VS 2017
- Create a new "WPF App (.NET Framework)" C# project
- Edit the csproj file to look like:
Project file:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
<TargetFramework>net45</TargetFramework>
<ProjectGuid>{030D04DA-D603-4D4C-95F7-B6F725A6829E}</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
- Add a button called "button1" to MainWindow.xaml as below:
MainWindow.xaml
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Name="button1" Width="100" Height="50">Click me!</Button>
</Grid>
</Window>
- Try and set the button caption in code in "MainWindow.xaml.cs".
You will see that intellisense does not recognise that the button is defined:
However, the project builds and runs successfully (note you will need to run the executable manually - F5 doesn't work...)