I have a library that is shared between .NET Core 3.1 and .NET Framework 4.7.2. I have found that when I run the .NET Core 3.1 Azure Function I can debug the library code, but when running the MVC app I cannot. Also, if I try to use intellisense to navigate to definitions within the library it will not take me to the code, but to the meta-data.
I've added a "full" debug type specifier to the top of the Library's csproj file like this and that does not help:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<DebugType>full</DebugType>
</PropertyGroup>
I have other similar libraries that do not have this issue and have tried copying over some config attributes, but nothing seems to help. How might this be fixed?
I am using the latest version of VS 2019 and I have noticed that the PDB file size has increased since making the DebugType full. If I try to load the symbols manually using the Modules window it tells me a debug file of the correct type cannot be found.
It turns out I had to sign the assembly or give it a guid for my Framework app to navigate into it, or debug it. The csproj looks like this now at the top:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{<some guid>}</ProjectGuid>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<DebugType>full</DebugType>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile><some snk file name>.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
The old options to have VS generate the strong signing stuff for you can still be accessed in VS by right-clicking on the project and selecting Properties.
Related
I have a Blazor app that the generated DLL does not get updated with the referenced <AssemblyVersion>2022.01.14.1</AssemblyVersion> found in the .csproj file.
Nor does the <FileVersion> and <Version>
Microsoft Visual Studio Professional 2022 (64-bit)
Version 17.0.5
How do you check the version, from the code or from the file properties?
I tried the scenario you described on a Blazor application, and after building the project in the properties of the .dll file I can see all versions I set in the .csproj
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyVersion>2022.01.14.1</AssemblyVersion>
<FileVersion>2022.01.14.1</FileVersion>
<Version>3.3.3.3-xyz</Version>
And the result can be seen in the image below:
Is it possible that some other external process changes the version in the files after you build?
How to link UWP Class Library into an WPF Application?
I have created an UWP Class Library with a single test class. I have an WPF .NET application which wants to consume that class library. What are the steps I need to follow?
Following this tutorial, I wanted to add library MyLib in my Application MyApp. But I am finding following compiler errors,
Severity Code Description Project File Line Suppression State
Error NU1201 Project MyLib is not compatible with netcoreapp3.1
(.NETCoreApp,Version=v3.1). Project MyLib supports:
uap10.0.19041 (UAP,Version=v10.0.19041) MyApp C:\Users....\MyApp.csproj
##UPDATE
After adding following code,
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MyLib\MyLib.csproj" />
</ItemGroup>
</Project>
as suggested by TamBui in the answer, I am getting build error. However there have been two compiler warnings from the beginning. Sharing if it can give any clue,
Warning NETSDK1137 It is no longer necessary to use the
Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk
attribute of the root Project element to
'Microsoft.NET.Sdk'. MyApp C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 376
Warning MSB3270 There was a mismatch between the processor
architecture of the project being built "MSIL" and the processor
architecture of the reference
"C:\Users...\MyLib\bin\x64\Debug\MyLib.dll",
"AMD64". This mismatch may cause runtime failures. Please consider
changing the targeted processor architecture of your project through
the Configuration Manager so as to align the processor architectures
between your project and references, or take a dependency on
references with a processor architecture that matches the targeted
processor architecture of your project. MyApp C:\Program Files
(x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2123
A WPF application cannot reference a UWP class library. In short, the two different platforms or frameworks are not compatible with each other.
You should change the target framework of your class library (MyLib.csproj) to either .NET Standard or the same framework that your WPF app targets:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
You need to add the AssetTargetFallback that matches your UWP project's target version to your WPF project's PropertyGroup. Select your WPF project in the Solution Explorer, and you will be able to edit the project's properties.
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_68824006</RootNamespace>
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
<UseWPF>true</UseWPF>
</PropertyGroup>
I have migrated project of WPF in Asp.Net framework into Asp.Net core. Existing .net projects have AssemblyInfo.cs inside properties folder.when creating new WPF project using "dotnet new wpf". AssemblyInfo.cs file gets added.
AssemblyInfo.cs in .Net framework have all information but the one in dot net core doesn't have any information
Planning to delete new one created for core since getting build issue as "duplicate ThemeInfo attribute" and disable old one which got migrated from .Net framework using add below properties in the csproj
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Need to know if is this needed for Net core project.
AssemblyInfo.cs is useful, but it's not necessary.
In .NetCore you can manage AssemblyInfo from the .csproj file instead of AssemblyInfo.cs file. The AssemblyInfo.cs file will be autogenerated in obj folder for you. All you need to do is to set its properties in the csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>myAppName</AssemblyName>
</PropertyGroup>
</Project>
The compiler will complain about duplicate properties if there is an AssemblyInfo.cs file present in your project with any properties set. In this case you should set GenerateAssemblyInfo to false (so that it doesn't auto-generate an x.AssemblyInfo.cs into obj folder):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>myAppName</AssemblyName>
</PropertyGroup>
</Project>
You can choose to handle the assembly information manually (through AssemblyInfo.cs files instead of through .csproj file) just by setting auto-generate attributes to false. For example you may set GenerateAssemblyInfo to false to prevent auto-generation of the AssemblyInfo.cs or you may set GenerateAssemblyTitleAttribute to false to prevent auto-generation of Title attribute inside AssemblyInfo.cs. This means you can set the assembly information in both AssemblyInfo and csproj. This comes in handy when you want to share a common set of information between different projects, while being able to change some info in each of them. (You can't set a property twice though, but still this is a useful feature)
Just a side note: Since you've migrated to .NetCore you might as well want to migrate your csproj into Project SDK format, if you haven't already done it. Then you will notice a lot of clutter disappearing from csproj making it more readable and easier to maintain, putting more focus on those mentioned properties.
There is a way to do the same thing in Classic .Net Applications: https://github.com/dasMulli/AssemblyInfoGenerationSdk
Properties/AssemblyInfo.cs should be removed when you upgrade your project from .NET Framework to .NET Core or .NET 5 or .NET 6. As you saw, you will get build errors otherwise. Instead, the info that was in there now should be stored directly in the .csproj file.
I have a solution with several executables in it (say, MainApp.exe and Tool.exe).
The main goal is to ensure that the tool (Tool.exe) with its dependencies is copied to the main executable directory during build.
I used the advice from here, and it seemed to work with the older Visual Studio version (at least with some version prior to 16.8).
My project structure (simplified) looks like this:
Solution.sln
├ MainApp.csproj
├ Tool.csproj
| └ App.config
└ ToolLib.csproj
Tool project contains App.config file, and references ToolLib project.
My MainApp.csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Tool/Tool.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
</ProjectReference>
</ItemGroup>
</Project>
After upgrading to 16.8 after the compilation the file Tool.exe was indeed copied to the output directory, but neither its dependency ToolLib.dll nor Tool.config was copied to the output directory any more.
Is this a bug or intended behaviour? What is the proper way to ensure that the whole Tool with all the needed dependencies is copied to the MainApp's output dir?
Added test project reproducing the problem here: https://github.com/vladd/ReferenceOutputAssembly
What you gave is too old and it is not suitable for VS2019. And all your projects target to net core 3.1. I have tested your project both in VS2019 16.8 , VS2019 16.7, even 16.6 which all act the same behavior as you described. Only contain the Tool.dll and Tool.exe.
So I wonder why you said before that the result of the build of ToolLib will be printed in the main project.
Actually, <ReferenceOutputAssembly>false</ReferenceOutputAssembly> will prevent the most main output files of the referenced project and its dependency project being copied into the main project.
Suggestion
You have to set it as true:
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
If you want to not copy ToolLib.pdb and Tool.pdb files into the main project, you could add these node on MainApp.csproj file:
<PropertyGroup>
<AllowedReferenceRelatedFileExtensions>*.pdb;.dll.config</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
If you also want to copy pdb files, you should add .pdb under AllowedReferenceRelatedFileExtensions.
<AllowedReferenceRelatedFileExtensions>.pdb;.dll.config</AllowedReferenceRelatedFileExtensions>
Update 1
I tried your suggestion but with it the files Tools.deps,json and
Tool.runtimeconfig.json are not copied, so running the tool fails.
Add this on MainApp.csproj file:
<PropertyGroup>
<AllowedReferenceRelatedFileExtensions>.pdb;.dll.config;.runtimeconfig.dev.json;.runtimeconfig.json</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
I'm trying out WPF .NET Core for the first time, and one of the things I always do in a new WPF .NET Framework project is turn on the console, but I receive an error when I try to do this in .NET Core.
In traditional WPF, targeting .NET Framework, this was fairly simple;
Set the Build Action for App.xaml to Page
Define a Main method somewhere, and tag it with the STAThreadAttribute
In the project settings, set the output type to Console Application, and set the Startup object to wherever you put the Main method
I replicated these steps in the WPF .NET Core, but I get an error when I try to change the Build Action for App.xaml
The error (it occurs immediately after selecting Page in the dropdown in the Properties window):
An error has occurred while saving the edited properties listed below:
Build Action
One or more values are invalid.
Cannot add 'App.xaml' to the project, because the path is explicitly excluded from the project
(C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.NET.Sdk.WindowsDesktop.targets (45,5)).
Does anyone know a way around this, or another way to enable the console in WPF .NET Core?
Setting the following properties will make your WPF application a "Console Application"
<PropertyGroup>
<OutputType>Exe</OutputType>
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
</PropertyGroup>
The SDK automatically change OutputType from Exe to WinExe for WPF and WinForms apps. See https://learn.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/5.0/automatically-infer-winexe-output-type
After some trial and error, I figured out that the .csproj file got messed up. I don't know how exactly it went wrong, I suspect it had to do with editing the project through its Properties window in that version of VS2019.
I edited the .csproj by hand, and it works if it looks as follows:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon />
<StartupObject>ProjectName.App</StartupObject>
</PropertyGroup>
<ItemGroup>
<Page Include="App.xaml"></Page>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Remove="App.xaml"></ApplicationDefinition> <--- key part
</ItemGroup>
</Project>
I checked the .csproj file for a working .NET Framework project, and the key seems to be removing App.xaml as ApplicationDefinition by hand, as the .NET Framework .csproj did not have that section in it.