-
Notifications
You must be signed in to change notification settings - Fork 89
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
Globbing with DependentUpon #169
Comments
By the way, DependentUpon is applied to my XAML rule (and worked fine in VS2015) /~https://github.com/Microsoft/VSProjectSystem/blob/b70104c4781749369c995a48f83e64607a0c6594/doc/extensibility/automatic_DependentUpon_wireup.md but it doesn't work with globbing. <ContentType
Name="PageXaml"
DisplayName="XAML Page"
ItemType="Page">
<NameValuePair Name="DependentFileExtensions" Value=".cs" />
<NameValuePair Name="DefaultMetadata_SubType" Value="Designer" />
<NameValuePair Name="DefaultMetadata_Generator" Value="MSBuild:Compile" />
</ContentType>
<ItemType Name="Page" DisplayName="XAML Page" />
<FileExtension Name=".xaml" ContentType="PageXaml" /> |
Ok, I've found a good workaround - added this to the CSPROJ: <Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
<SubType>Code</SubType>
</Compile> |
This pattern may also be useful for T4 templates and their generated output. What does |
For those who're also using ReSharper it might be helpful - it seems I've found a bug which is affects only ReSharper - it reports for every named XAML element that the field is already declared - because it looks into the <-- this not works for ReSharper for some reason -->
<Compile Include="**\*.cs" />
<Compile Remove="obj\**" /> Use this instead: <Compile Include="**\*.cs" Exclude="obj\**" /> |
The resulting files globbing code for including <Compile Include="**\*.cs" Exclude="obj\**" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="**\*.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page> Please note that you need to define the |
In order to support Depend Upon items in combination with globs, we added a new feature - dynamic depend upon items - the dependency between files is calculated dynamically when project is loaded and doesn't get persisted in the project file. Documentation is pending, so here is a quick overview: You can use the existing implementation of IDependentFilesProvider that uses metadata defined in the project items schema to identify dependent files: <ContentType
Name="aaaSourceFile"
DisplayName="aaa source file"
ItemType="aaaCompile">
<ContentType.Metadata>
<NameValuePair Name="DependentExtensions" Value=".aaa.cs;.aaa.txt" />
</ContentType.Metadata>
</ContentType> This snippet will make .aaa.cs and .aaa.txt files to be displayed as dependent on .aaa files For more advanced relationships you can implement a new IDependentFilesProvider. |
@adrianvmsft, thanks! I just checked and it doesn't work for me in the latest VS2017 RC - dependent <ContentType
Name="PageXaml"
DisplayName="XAML Page"
ItemType="Page">
<ContentType.Metadata>
<NameValuePair Name="DependentExtensions" Value=".xaml.cs" />
</ContentType.Metadata>
</ContentType> |
You're right, I forgot to mention that you also need to define the DynamicDependentFile capability. Sorry about that. Could you try adding the following to your project (e.g. in the .targets file): <ProjectCapability Include="DynamicDependentFile"/> |
@adrianvmsft, thanks! It works now as expected. Regards! |
Great! I am glad that it worked! |
Here is the PR with the documentation update, in case you would like to take a look: #187 |
Anyone got this working? I'm able to compile it but I lost intellisense in VS 2017. This is my csproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
<OutputType>winexe</OutputType>
<TargetFramework>net462</TargetFramework>
<DebugType>Full</DebugType>
<ApplicationIcon>res\ico\icon.ico</ApplicationIcon>
<OutputTypeEx>winexe</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TransformOnBuild>True</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<ItemGroup>
<!-- App.xaml -->
<ApplicationDefinition Include="App.xaml" SubType="Designer" Generator="MSBuild:UpdateDesignTimeXaml" />
<!-- XAML elements -->
<Page Include="**\*.xaml" SubType="Designer" Generator="MSBuild:UpdateDesignTimeXaml" Exclude="App.xaml" />
<Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" />
<Compile Include="$(IntermediateOutputPath)**\*.g.cs" Visible="false" />
<None Include="$(ProjectDir)obj" Visible="false" />
<!-- Resources -->
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />
<!-- Settings -->
<None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
<Compile Update="Properties\Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" />
<None Update="App.config">
<TransformOnBuild>true</TransformOnBuild>
</None>
<None Update="App.Debug.config">
<IsTransformFile>True</IsTransformFile>
</None>
<None Update="App.Release.config">
<IsTransformFile>True</IsTransformFile>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Publish\**" />
<EmbeddedResource Remove="Publish\**" />
<None Remove="Publish\**" />
<Page Remove="Publish\**" />
</ItemGroup>
<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
</PropertyGroup>
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project> |
@bdovaz I responded there dotnet/project-system#1467 (comment) |
Here is a fun example of bad behaviour of globbing and the project system. I have
where I18NReactive is a custom single file generator I wrote. The globbing and dependencies work at first glance. Then I right click and select run custom tool to regen the
that's kinda wierd no? I also tried
|
I made the above comment a new issue at dotnet/project-system#2873 |
@adrianvmsft Hello, I'm wondering why this feature looks so xaml-centered? At the documentation page there is nothing about how to make this work with other file types. For example, I'd like to link common appsettings json files which are not linked automatically (e.g. appsettingsCommon.json and appsettingsCommon.Development.json ). How do I accomplish this with this feature? |
I've read this page about globbing in VS 2017 RC /~https://github.com/Microsoft/VSProjectSystem/blob/master/doc/overview/globbing_behavior.md and very happy with how everything works. But...
Are there any way of using DependentUpon with globbing?
Currently I have these rules:
But it seems DependentUpon is not working this way - solution explorer displays
Foo.xaml
andFoo.xaml.cs
as the separate files, but I needFoo.xaml.cs
to be nested inFoo.xaml
.There is a warning generated:
The parent file, '*.xaml', for file 'Foo.xaml.cs' cannot be found in the project file.
Regards!
The text was updated successfully, but these errors were encountered: