Giter Club home page Giter Club logo

Comments (19)

inthemedium avatar inthemedium commented on July 19, 2024 3

@AArnott , figured out the issue. I needed to add <UseWPF>true</UseWPF> for the project to be formally recognized as a SDK-style WPF project. After that the new flag works

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>        
    <TargetFrameworks>net45</TargetFrameworks>
    <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
    <UseWPF>true</UseWPF>
....

from cswin32.

AArnott avatar AArnott commented on July 19, 2024 1

@nick-beer, your question sounds unrelated to this source generator and more appropriate for the WPF audience. Can you try posting your question over on the dotnet/wpf repo?

from cswin32.

nick-beer avatar nick-beer commented on July 19, 2024 1

@AArnott - Shoot, I'm sorry. I'm not sure what repo I thought I was in - I just followed google from a search for IncludePackageReferencesDuringMarkupCompilation - a property that looked suspicious when debugging a build issue. I'll post to another repo - thanks!

from cswin32.

anti-matter avatar anti-matter commented on July 19, 2024 1

Ok, thanks @AArnott, I think we figured it out.

In the sample, the using path is Microsoft.Windows.SDK, but for some reason, in our project, it must be Microsoft.Windows.Sdk. Using that camel case seems to have fixed our issue. Such a small thing. :)

from cswin32.

lindexi avatar lindexi commented on July 19, 2024 1

It seems to be fixed in dotnet 6.

from cswin32.

AArnott avatar AArnott commented on July 19, 2024 1

True. The .NET 6 SDK includes the new behavior as on by default whereas .NET 5 SDK had it off by default.

from cswin32.

AArnott avatar AArnott commented on July 19, 2024 1

@MddMBorg Check out #601, which sounds like what you're hitting.

from cswin32.

nick-beer avatar nick-beer commented on July 19, 2024

I believe I'm running into some form of this issue with a package that contains C# files in its contentFiles (with buildAction="Compile"). Setting IncludePackageReferencesDuringMarkupCompilation (when using 5.0.102, as described) does not seem to help. Are contentFiles still broken with this workaround?

from cswin32.

anti-matter avatar anti-matter commented on July 19, 2024

Hello, we're trying to use CsWin32 with our .NET 5.0 WPF app and the steps above DO NOT work (we followed them exactly). We still continue to get the following error. What are we missing?

error CS0234: The type or namespace name 'SDK' does not exist in the namespace 'Microsoft.Windows' (are you missing an assembly reference?) [C:\Users\micha\source\repos\teams-client\windows-gui\windows-ui\Windows-UI_gbumtqzv_wpftmp.csproj]

Thanks in advance!

from cswin32.

AArnott avatar AArnott commented on July 19, 2024

@anti-matter, I have attached a .zip to a sample that works in our testing to the issue description. Does that work on your machine with dotnet build?

from cswin32.

anti-matter avatar anti-matter commented on July 19, 2024

Thanks @AArnott for the zip. That simple project works fine for me, but I still cannot get it to work in my project. I tried to find a setting that our project has set that might be causing our build to fail, but no luck.

I did notice too that intellisense still claims there's an error with Microsoft.Windows.SDK in the sample project, but the compiler seems to ignore that it's missing. In my case, the compiler does not ignore it.

Is there a release where we expect this issue to be resolved in WPF so the work-around is not necessary?

thx.

from cswin32.

AArnott avatar AArnott commented on July 19, 2024

but the compiler seems to ignore that it's missing. In my case, the compiler does not ignore it.

The compiler can't and isn't ignoring it. The compiler sees it where the IDE language service does not. So given the sample project works for you at the command line but your project does not work at the command line tells us that there is something peculiar with your project that prevents the source generator from running. I suggest you compare the build logs between the sample and your project. Use the /bl switch and use the viewer at http://msbuildlog.com and focus on the Csc task invocation's Analyzers parameter to see if there are differences, to start with.

Once you get the command line build working on your project, we can focus on what remains in the IDE that could be broken, but you should probably start with trying out 16.9 Preview 3 to see if that works for you, as a lot of source generator bugs have been fixed in that release.

Is there a release where we expect this issue to be resolved in WPF so the work-around is not necessary?

The fix is already released, but it requires opt-in via the property documented above.
It may be the default behavior in the .NET 6 SDK, but I haven't heard that confirmed.

from cswin32.

AArnott avatar AArnott commented on July 19, 2024

@anti-matter What sample uses Microsoft.Windows.SDK with all-caps for SDK? That's a bug and wouldn't work anywhere. The sample .zip in the issue description doesn't have this issue -- I just checked.

from cswin32.

inthemedium avatar inthemedium commented on July 19, 2024

@AArnott does this fix apply to WPF non-core (WPF framework?)?

i.e.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>        
    <TargetFramework>net45</TargetFramework>
    <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
   ...

I didn't see the property when searched the binlog, so I'm guessing no. Is there a place I can file a bug to get this fixed there too?

from cswin32.

AArnott avatar AArnott commented on July 19, 2024

@inthemedium, I'm told that it should work, provided you are building with the required SDK version.

I didn't see the property when searched the binlog

Then something else is wrong, since you are setting the property, it should be there.

from cswin32.

zhylmzr avatar zhylmzr commented on July 19, 2024

If anyone has this problem in .NET 6, try to install 0.1.422-beta version.

from cswin32.

AArnott avatar AArnott commented on July 19, 2024

@zhylmzr, that's quite an old version of CsWin32. Do you find it works better than the latest version?

from cswin32.

zhylmzr avatar zhylmzr commented on July 19, 2024

@AArnott The newst version doesn't work in my environment, same error message.

from cswin32.

MddMBorg avatar MddMBorg commented on July 19, 2024

Does anyone have a fix for this in .NET 6? I have a WPF project but receive the following when compiling:

error CS0101: The namespace 'NameSpace' already contains a definition for 'Type'

Where the namespace and type is defined in my Source generator. This had no issues in .net 472 with SDK style project, but have recently upgraded.

The project has the following tags:

	<PropertyGroup>
		<OutputType>WinExe</OutputType>
		<TargetFramework>net6.0-windows</TargetFramework>
		<UseWPF>true</UseWPF>
		<UseWindowsForms>true</UseWindowsForms>
		<deterministic>false</deterministic>
		<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
		<EnableNETAnalyzers>true</EnableNETAnalyzers>
		<AnalysisLevel>none</AnalysisLevel>
		<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
	</PropertyGroup>

from cswin32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.