Convert Project to SDK style and referenced project cannot be found - c#

Converting project TEditor in my larger solution to use SDK with target frameworks including netstandard2.0.
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;MonoAndroid90</TargetFrameworks>
In visual studio I told different project BASE to reference that project TEditor. Shows up in dependencies.
But when I have Using TEditor in CS code in Base, it does not find the TEditor (error on Using TEditor;). Furthermore when I build Base I get CS0246 error:
...\PageModel.cs(12,7,12,14): error CS0246: The type or namespace name 'TEditor' could not be found (are you missing a using directive or an assembly reference?)
Base is using netstandard2.0
netstandard2.0
and both projects use
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
Lastly I am getting DLL's produced from TEditor in correct bin/debug folders:
1>------ Rebuild All started: Project: TEditor, Configuration: Debug Any CPU ------
1>TEditor -> C:\Users\Brent\Documents\MyDataApp\Teditor\bin\Debug\netstandard2.0\TEditor.dll
1>TEditor -> C:\Users\Brent\Documents\MyDataApp\Teditor\bin\Debug\monoandroid90\TEditor.dll
What am I missing and how can I diagnose further?

Well, I found out my TEditor.dll was empty when I looked at the object browser. With the new SDK setup I didn't have the correct Includes and it compiled and looked happy, because it wasn't including any code.

Related

Trying to get example from Microsoft Docs on WPF to work in local machine

I'd like to get this example running from the Microsoft Docs.
In order to do so I made a new directory called inotifyproperty-changed-example. In this project I generated a WPF solution by running the following commands:
dotnet new wpf
dotnet new sln
dotnet sln add inotifyproperty-changed-example.csproj
Then I removed all XAML and CS files by running rm *.cs; rm*.xaml as it is my understanding the example code is self-contained.
Then I copied the example code in the link to a file called App.cs and changed the namespace to match my own, namely inotifyproperty_changed_example.
The contents of the CSPROJ file are as follows:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>inotifyproperty_changed_example</RootNamespace>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
Unfortunately when I try to run the solution using dotnet run I get errors:
error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
The type or namespace name 'Form' could not be found (are you missing a using directive or an assembly reference?)
...
I'm really at a loss as to why this won't build. More generally speaking, I am asking this question because I'm unable to reproduce many of the examples provided in the WPF documentation, so I need a place to start.
How can I get the example to work?
You are linking to a Windows Forms example, not a WPF one.
Create the WPF project using the default template and don't remove any files. Then add the DemoCustomer class from the example to the project. You cannot use the Form1 class as it's not WPF. Instead you could modify the MainWindow class as per your requirements.
As far as the INotifyPropertyChanged interface is concerned, there is no difference between WPF and Windows Forms. This interface is not platform specific.

Can a C# MsTest project be converted to Microsoft.NET.Sdk project format?

I've got a C# MsTest project that targets net48. I've change the project it tests to the newer style Microsoft.NET.Sdk csproj format and that went ok. Now I want to convert the unit test project too.
I get errors about namespace Microsoft.VisualStudio.TestTools.UnitTesting cannot be found: error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft'
To solve that, I added the assembly reference to the csproj:
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
But I get errors that it can't be found.
warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
This was found ok when the old csproj format was used.
How can I get this assembly reference to be found, or what is the preferred way of making this work?
Here are 3 possible solutions:
Upgrade to MSTestV2 by adding the nuget packages MSTest.Framework and MSTest.TestAdapter.
CAVEAT: MSTestV2 only supports .NET Framework 4.5 and later.
Continue using MSTestV1 by helping visual studio find the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll reference, by adding this to your csproj:
<PropertyGroup><AssemblySearchPaths></AssemblySearchPaths></PropertyGroup>
see this explanation for why that's necessary
Continue using MSTestV1 by browsing to the dll's path when adding the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Depending on your version of VS the path will be something like: Program Files\Microsoft Visual Studio\2019\Professional\Common7\IDE\PublicAssemblies
I used #2 because we target net40 and have multiple developers working on different versions of VS.
Add the nuget packages MSTest.TestFramework and MSTest.TestAdapter.
The test framework allows the unit tests to build and brings in the required namespaces. The second allows the test runner to find the tests in the project.

visual studio compiler errors on __IOS__ when building on windows

I am getting a compiler error I do not understand. I have a dotnet core (.NET standard 2.0) project (originally created on mac). I am using visual studio on Windows 10 to edit/build it. I get a compile error on code in a define. I was expecting the code to be ignored during the build, like the editor displays.
Here's the class.
internal sealed class PoolAsync : IDisposable
{
#if __IOS__
[MonoPInvokeCallback(typeof(EventCompletedDelegate))]
#endif
}
I've checked the configuration managers, project properties and I do not have IOS defined. Not sure why I am getting these errors:
1>Pool\Async.cs(18,10,18,29): error CS0246: The type or namespace name 'MonoPInvokeCallbackAttribute' could not be found (are you missing a using directive or an assembly reference?)
1>Pool\Async.cs(18,10,18,29): error CS0246: The type or namespace name 'MonoPInvokeCallback' could not be found (are you missing a using directive or an assembly reference?)
I do not get the errors when building from the command line:
any ideas?
Thnx
Matt
edit: if you wish to see the entire project, you can pull from my github
I have fixed my problem. The project (csproj) was set to target framework of netstandard2.0. I changed this to netcoreapp2.1 and all of those errors went away.
I had to manually edit the csproj file. The old target framework entry looked like this:
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net452;xamarinios10</TargetFrameworks>
</PropertyGroup>
and updated to:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
This does mean I no longer have xamarian support for iOS, however I am ok with that for the moment. The projects build on command line and in visual studio for both mac and windows.
Thnx
Matt

visual studio 2013 on rebuild ddl Issue

I have a asp.net solution which consists of multiple class library whose dll' are been used in one web application.When I build and rebuild the class library I don't face any issue, later when I try to build and rebuild the solution few of my dll files gets deleted from bin.Tried adding reference path but in vein.
Warning : Could not resolve this reference. Could not locate the assembly "classlibrary2". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. classlibrary1
Error 10 The type or namespace name 'Classlibrary1' could not be found (are you missing a using directive or an assembly reference?)
Note:All projects are in same framework

MSBuild cannot find a reference

I'm currently trying to figure out why MSBuild is not able to compile one of our unit test dlls. The problem is only occuring with this DLL and not with the other unit test projects.
This is the output I receive from TeamCity when the build fails:
[10:38:55]: NAnt output:
[10:38:55]: [exec]
[10:38:55]: [exec]
[10:38:55]: [exec] "C:\Robinson\trunk\Projects\Robinson\Robinson.sln" (default target) (1) ->
[10:38:55]: [exec] "C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj" (default target) (19) ->
[10:38:55]: [exec] (CoreCompile target) ->
[10:38:55]: [exec] Modules\SecurityModuleTests.cs(10,30): error CS0234: The type or namespace name 'Modules' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] Modules\SecurityModuleTests.cs(197,39): error CS0246: The type or namespace name 'SecurityModule' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] TranslateTests.cs(10,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] IPETests.cs(8,30): error CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] Pages\BasePageTest.cs(6,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] Pages\BasePageTest.cs(7,30): error CS0234: The type or namespace name 'Pages' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] ServiceAsmxTests.cs(9,30): error CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] ServiceAsmxTests.cs(10,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] Pages\BasePageTest.cs(16,17): error CS0246: The type or namespace name 'basepage' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec] ServiceAsmxTests.cs(22,17): error CS0246: The type or namespace name 'Service' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj]
[10:38:55]: [exec]
[10:38:55]: [exec] 2075 Warning(s)
[10:38:55]: [exec] 10 Error(s)
[10:38:55]: [exec]
[10:38:55]: [exec] Time Elapsed 00:01:40.06
The project TenForceExecutionTests is a simply DLL that contains several UnitTests of the MBunit Framework. This project has a reference to TenForceExecution which is a web application project and another reference to TenForce.Execution.Test, which is another DLL containing logic for both projects.
When we compile everything on the development machine, it works without problems and the compile occurs without errors. On the build agent however this seems to fail...
INFO
Target Framework : .NET4
OS : Windows XP 32bit
Windows 7 SDK Installed
EDIT
Did a clean checkout, and Visual Studio is able to build the entire solution, msbuild however cannot.
EDIT 2
Checked the dependencies:
There is a project dependency between the projects
There is a solution dependecy between the projects
EDIT 3
When I remove the reference to the webApplication project, and replace it with a reference to the compiled DLL of that project, the errors dissapear and the project compiles fine with MSBuild.
EDIT 4
I've ran the entire build from msbuild through a LOG and took a look at the specific task for compiling the project that's giving problems:
Task "Csc"
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\ASP.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\BUL\bin\Debug\BUL.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\BULTest\bin\Debug\BULTest.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\DAL\bin\Debug\DAL.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\Framework\bin\Debug\Framework.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\Gallio.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\Iesi.Collections.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\LanguageResource\bin\Debug\LanguageResource.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\log4net.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\MbUnit.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\NHibernate.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\PresentationBridge\bin\Debug\PresentationBridge.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\PresentationBridgeTest\bin\Debug\PresentationBridgeTest.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\System.Data.SQLite.DLL /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Extensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Services.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\TenForce.Execution.Test\bin\Debug\TenForce.Execution.Test.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\WatiN.Core.dll /debug+ /debug:full /optimize- /out:obj\Debug\TenForceExecutionTests.dll /target:library Modules\SecurityModuleTests.cs TestRunSetup.cs TranslateTests.cs WebBaseTest.cs MetaTests.cs IPETests.cs Pages\BasePageTest.cs Properties\AssemblyInfo.cs ServiceAsmxTests.cs Settings.Designer.cs "D:\Users\arne.de.herdt.TENFORCE2\AppData\Local\Temp\6\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
From what I can tell, the actuall WebApplication is NOT included in the reference list.
Had the same issue today, ended that the project that could not be referenced had a different platform specified, x86 where the other projects where Any Platform. To get around this, I had to set the parameter with /p:Platform="Mixed Platforms". You can see what VS uses by going to Configuration Manager and looking at the Active Solution Platform selected in the top right.
Apparently this seems to be a known problem in MSBuild as more people have issues with this.
I still haven't received a valid reply from Microsoft regarding this, but the discussion was continued here : http://social.msdn.microsoft.com/Forums/en-CA/msbuild/thread/434abf1a-30db-4b13-8062-13755898dd71
I also found a similar reference issue when building an UWP appx package. There are a lot of error messages look like:
App.xaml.cs(6,15): error CS0234: The type or namespace name 'ApplicationModel' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
If opening the sln file with VS2017, it builds no problem.
I did two things to fix this issue:
I noticed that the original solution requires winSDK 10.0.18362, but on my build machine, I don't have it. If opening with VS2017, it asks me to re-target the SDK to an installed older version. I think the msbuild may not be able to do the re-target, so I just downloaded and installed the required winSDK 18362.
I added a "/t:restore" option to the msbuild command line, and run the msbuild twice:
msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64" /t:restore
msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64"
For restore, please refer to https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
I know this is an old post, but I came across it today, so thought I would offer feedback for anyone else.
I've encountered this a few times and found that changing the Target Framework from .NET Framework 4 Client Profile to just .NET Framework 4 does the trick.
I encountered same issue (Build successfully in Visual studio, but fail by MSBUILD).
After tried different solutions mentioned in this questions but failed.
Fortunately finally I found adding -tv:version resolve the errors.
For my project, the <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> in my A.csproj is v4.0, so I used the command like msbuild A.csproj -tv:4.0 then succeeded to compile the projects.
Below are the struct of my solution:
Project A: startup project and target framework version=v4.0
Project B: reference project, its target framework version=v3.5
Project C: reference project, its target framework version=v3.5
It seems if not telling the specific target framework version to MSBUILD when exists multiple versions, sometimes it will get messed up.
If you do a clean checkout to a new folder on your machine does it work over there too?
Most times these problems occur because you have a reference to something that is available locally but not in source control. This is a good check to see if everything that is needed for building your project is correctly referenced and under source control.
I have also experienced the issue that building from VS is not always the same as simply using msbuild. What helped me then is to create a log of the msbuild run (/fl switch) and check the log and trace down the build steps and try to find the problematic task.
I inspect the dll properties missed and I see that the assembly name have the same name of the default namespace.
Then I change the assembly name to a different one and I solved my problem.
I have also experienced the same issue.
I really doubt why MSBuild throws missing assembly reference when ever we run the solution file through MSBuild and Jenkins but it works like a charm in the Visual Studio, After fighting for two days I found a conclusion for this.
I wrote a batch script to run the Solution file first through Visual Studio and then ran the Solution file. It is not working fine.
All you need to do is to call the batch script and then run the MSBuild/Jenkins.
Batch script :
cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
devenv "C:\Program Files (x86)\Jenkins\workspace\TFS\Product\Soluttion.sln" /Rebuild
devenv: To run the Visual Studio in Command line.
Note: you really need Visual Studio if your running MSBuild/Jenkins in the server.
Mail me for any issues regarding this..........
I encountered this error message when I built a solution with MSBuild in Release mode, even though Debug mode worked fine and both worked in Visual Studio. Turned out in the solution settings the project was not configured to be built for "Release|Mixed Platforms" or "Release|Any CPU".
I have tried using AnyCPU and Prefer-32 bit, it still didn't work. Also tried with AnyCPU without checking Prefer-32 bit but nothing worked. I was having this issue when Deploying my code using the Bamboo. I made sure my packages are all checked in to the code(as my nuget restore in bamboo have an issue) and make sure my dll references in the project are looking at the packages in their paths. I checked in my packages by removing the /packages from the .gitignore file. Also, updated my packages.config file in the project to mention the package and the version to use.
For Ex:
Also, made sure the Agent on which the Deployment task is running, it has the needed .NET framework version. With the above all changes, I could resolve this reference issue.
My project configuration file "csproj" had two <ItemGroup> sections with <ProjectReference>s
This error has gone when I merged these <ItemGroup> sections.
Had the same problem with a Visual Studio 2019 project.
The issue was solved by migrating project references from packages.config to PackageReference.
From the Microsoft Docs:
Open a solution containing project using packages.config.
In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference....
[...]
Note
Before migration begins, Visual Studio creates a backup of the project to allow you to roll back to packages.config if necessary.

Categories

Resources