我有一个带有 2 个 Windows Phone 7 项目的 Visual Studio 解决方案。一个是主项目,另一个从第一个链接其 xaml 页面。
我尝试修改第二个项目的 .csproj 文件,以便通过自定义任务预处理其链接页面。我的修改基于这篇博文的示例解决方案:
Xaml 页面确实由我的自定义任务处理,但输出文件不用于继续编译过程。我想这是代码的相关部分:
<ItemGroup>
<ProcessedPages Include="@(Page->'%(Link)')" />
<!-- Remove the original (linked) pages so that they are not compiled. -->
<Page Remove="@(Page)" Condition="('%(Page.Link)' != '')" />
<!-- Include the processed pages instead. -->
<Page Include="@(ProcessedPages)" />
</ItemGroup>
如何修改它以便 MarkupCompilePass1 使用 PreprocessorTask 任务的输出文件?
顺便说一句,我在编译期间没有得到 @(Page->'%(Link)') 的值。
完成项目文件以供参考:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="XamlPreprocessor.PreprocessorTask" AssemblyFile="C:\Users\Louis\Documents\visual studio 2010\Projects\XamlPreprocessor\XamlPreprocessor\bin\Debug\XamlPreprocessor.exe" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C835DF63-2335-4946-B343-186E556C4FEC}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ProcessorTest</RootNamespace>
<AssemblyName>ProcessorTest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
<XapFilename>ProcessorTest.xap</XapFilename>
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
<SilverlightAppEntry>ProcessorTest.App</SilverlightAppEntry>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;WP8</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone" />
<Reference Include="Microsoft.Phone.Interop" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Xml" />
<Reference Include="mscorlib.extensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Appli2\MainPage.xaml.cs">
<Link>MainPage.xaml.cs</Link>
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="..\Appli2\Page2.xaml.cs">
<Link>Page2.xaml.cs</Link>
<DependentUpon>Page2.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="ApplicationIcon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Background.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SplashScreenImage.jpg" />
</ItemGroup>
<ItemGroup>
<Page Include="..\Appli2\MainPage.xaml">
<Link>MainPage.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="..\Appli2\Page2.xaml">
<Link>Page2.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<MarkupCompilePass1DependsOn>
$(CompileXamlDependsOn)
PreprocessXaml;
</MarkupCompilePass1DependsOn>
</PropertyGroup>
<Target Name="PreprocessXaml">
<!-- Run the preprocessor on every page that is added to the project as link. The processed file will be saved at the link position. -->
<!--<Exec Condition="('%(Page.Link)' != '')" Command="XamlPreprocessor.exe "%(Page.FullPath)" "%(Page.Link)""/>-->
<PreprocessorTask Symbols="$(DefineConstants)" File="%(Page.FullPath)" OutName="%(Page.Link)" Condition="('%(Page.Link)' != '')" />
<Copy SourceFiles="%(Page.Link)" DestinationFolder="C:\Users\Louis\Desktop\temp\" />
<ItemGroup>
<ProcessedPages Include="@(Page->'%(Link)')" />
<!-- Remove the original (linked) pages so that they are not compiled. -->
<Page Remove="@(Page)" Condition="('%(Page.Link)' != '')" />
<!-- Include the processed pages instead. -->
<Page Include="@(ProcessedPages)" />
</ItemGroup>
</Target>