2

I get numerous compiler warnings CS1591 Missing XML comment for publicly visible type or member ... in my Universal Windows Store App project in VS2015 for auto generated code files, e.g.

  • App.g.cs
  • App.g.i.cs
  • SomePage.g.cs
  • SomePage.g.i.cs

I know of the different approaches available to fix these warnings from showing up, but I can't get the specific approach mentioned in Quoc Lam's blog to work. The other possible solutions don't work for me, so what do I have to do make it work for my project?

There are a couple of things I still don't understand:

  • Where do I have to place the code lines containing the new target? I tried to put them into my Windows Phone project file (.csproj), but XamlGeneratedCodeFiles always seems to be empty (judging from diagnostic build output)
  • I also tried setting the AftetTargets attribute from XamlMarkupCompilePass1 to XamlMarkupCompilePass2, but still the same as above
  • Where is XamlGeneratedCodeFiles actually filled with data? Or do I misunderstand something?
  • Is XamlGeneratedCodeFiles the right variable to access?

I also looked at several of the msbuild .target files but got completely lost. Please let me know if you need further information that is still missing form this post.

Update

In addition to the accepted answer I post the working solution for my project as it wouldn't fit into a comment:

<Target Name="CodeWarningRemover" AfterTargets="MarkupCompilePass2">
    <ItemGroup>
        <CSFiles Include="**\*.g.cs;**\*.g.i.cs" />
    </ItemGroup>
    <Message Text="CSFiles: '@(CSFiles)'" />
    <Exec Command="for %%f in (@(CSFiles)) do echo #pragma warning disable > %%f.temp" />
    <Exec Command="for %%f in (@(CSFiles)) do type %%f >> %%f.temp" />
    <Exec Command="for %%f in (@(CSFiles)) do move /y %%f.temp %%f" />
</Target>
Gorgsenegger
  • 7,356
  • 4
  • 51
  • 89

2 Answers2

4

You could load the list of files to modify in the target wit ItemGroup :

<Target Name="CodeWarningRemover" AfterTargets="FindTheTagertToOverwrite">
    <ItemGroup>
        <Content Include="*.g.cs" />
        <Content Include="*.g.i.cs" />
    </ItemGroup>
    <Exec Command="for %%f in (@(Content)) do echo #pragma warning disable > %%f.temp" />
    <Exec Command="for %%f in (@(Content)) do type %%f >> %%f.temp" />
    <Exec Command="for %%f in (@(Content)) do copy /y %%f.temp %%f" />
</Target>

You need to find the target to overwrite : named "FindTheTagertToOverwrite" in the sample. It's the target used by the Universal Windows Store App project and it's build process or your custom build process. Sorry, I'm not familliar with this project

You could try with MarkupCompilePass1

Troopers
  • 5,127
  • 1
  • 37
  • 64
  • Unfortunately, `GeneratedFileToModify` is not a valid child element of `ItemGroup` - any ideas? – Gorgsenegger Dec 01 '15 at 07:40
  • Yes, replace `GeneratedFileToModify` by `CSFile`. I updated my response – Troopers Dec 01 '15 at 08:00
  • Hm... still doesn't work: "The element 'ItemGroup' in namespace 'http://...' has invalid child element 'CSFile' in namespace...". I tried to have the `Target` element as child of `Project` - is this wrong? – Gorgsenegger Dec 01 '15 at 14:29
  • yes `Taget` must be a child of `Project`. try with `Content` instead of `CSFile` – Troopers Dec 01 '15 at 14:46
  • Output looks like this: 2>Target "CodeWarningRemover: (TargetId:30)" in project "D:\...SomeProject.csproj" (target "PrepareResources" depends on it): 2>Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 2>Task "Exec" (TaskId:28) 2> Task Parameter:Command=for %%f in () do echo #pragma warning disable > %%f.temp (TaskId:28) 2> for %%f in () do echo #pragma warning disable > %%f.temp (TaskId:28) 2>Done executing task "Exec". (TaskId:28) ... Doesn't seem to do anything though (tried with MarkupCompilePass1 and 2). – Gorgsenegger Dec 01 '15 at 15:10
  • strange! your variable in the exec command is empty. Ensure you have changed `@(CSFile)` with `@(Content)` and ensure that `Content` in `ItemGroup` retrieve your files (perhaps you have a subdirectory to add) – Troopers Dec 02 '15 at 08:07
  • After trying a couple of things I ended up with your solution where I had to make a few amendments: For `AfterTargets` I used `MarkupCompilePass2` and for the children of `ItemGroup` I used `CSFiles` and changed the include to one line with `**\*.g.cs;**\*.g.i.cs`. Now I got rid of the warnings, but I'm still far from understanding `MsBuild` :) – Gorgsenegger Dec 03 '15 at 20:15
2

The "CodeWarningRemover" worked for my UWP projects until recently, when I created a solution configuration with a name that contained spaces. After some digging into MSBuild I was able to figure out the following:

<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
    <ItemGroup>
        <GeneratedCSFiles Include="**\*.g.cs;**\*.g.i.cs" />
    </ItemGroup>
    <Message Text="CSFiles: @(GeneratedCSFiles->'&quot;%(Identity)&quot;')" />
    <Exec Command="for %%f in (@(GeneratedCSFiles->'&quot;%(Identity)&quot;')) do echo #pragma warning disable &gt; %%f.temp &amp;&amp; type %%f &gt;&gt; %%f.temp &amp;&amp; move /y %%f.temp %%f" />
</Target>
Roland Weigelt
  • 123
  • 1
  • 8