I am trying to open a solution using Visual studio 2019 and visual studio 2017. All the projects in the solution are loading except for one. When trying to load the unloaded project i get an error in the output window as
TakstMVC.csproj : error : The imported project
"....build\MSBuild.Community.Tasks.targets" was not found. Confirm
that the expression in the Import declaration
"TakstMVC\.....build\MSBuild.Community.Tasks.targets" is correct,
and that the file exists on disk. TakstMVC\FluentMigrator.targets
When i tried to open using VS 2017 i saw a migration report which said
TakstMVC.csproj: The application which this project type is based on
was not found. Please try this link for further information:
http://go.microsoft.com/fwlink/?LinkID=299083&projecttype=E3E379DF-F4C6-4180-9B81-6769533ABE47
Part of the .csproj of the project is as below:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A4354F5C-ECF5-4621-AA9E-B91FE543F096}</ProjectGuid>
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TakstMVC</RootNamespace>
<AssemblyName>TakstMVC</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<MvcProjectUpgradeChecked>true</MvcProjectUpgradeChecked>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
I have the following installed in my computer
Microsoft .NET Framework 4.7.1 SDK
Microsoft .NET Framework 4.7.1 SDK Targeting Pack (ENU)
Microsoft .NET Core 3.1.1 - Windowsserver hosting
Microsoft .NET Core SDK 3.1.101 (x64)
Microsoft .NET Core SDK 2.2.207 (x64)
Microsoft .NET Core Runtime - 3.1.1
Microsoft .NET Core Runtime - 2.2.8
I tried to install dotnetfx35.exe but it doesnt even run when executed (not even a message or error).
The windows feature are as below:
How can I identify the target framework of the project and load it in visual studio successfully ? appreciate some advise on this.
The error is clear that you did not import the MSBuild.Community.Tasks.targets correctly on your local area. The reason is that you did not install MSBuild.Community.Tasks.targets on your PC or the import path from csproj file is incorrect.
You should check this document to install the right target.
First, remove xml node under csproj file like these:
<Import Project="..\build\MSBuild.Community.Tasks.targets" Condition="Exists('..\build\MSBuild.Community.Tasks.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\build\MSBuild.Community.Tasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\build\MSBuild.Community.Tasks.targets'))" />
</Target>
Second, install the msi file.
then, add these under the csproj file:
<Import Project="C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
Besides, you could also use nuget function. First, uninstall the nuget package if you have a old version on the project. Then, use the first suggestion to remove any previous import projects="xxx\MSBuildTasks.targets". After that, install the MSBuildTasks nuget package. That is the same.
Update
Try to You should change ..\..\ to ..\. Use the right path.
Or use this command under Tools-->Nuget Package Manager-->Package Manager Console
update-package -reinstall
Answer from the Customer
embarrassingly enough the whole issue was with the solution path where my solution was located in my local computer. I had a long path including a folder having two words as well. After trying everything else I moved the solution folder to C:\temp folder and the issue was no longer there. The error showed in VS was quite misleading. What a waist of time. Thank you for your efforts !
Related
I have a Visual Studio solution which has several projects. One of them, which is called Extensions is supposed to build a Nuget package. Problem is that if I use MSBuild to build the solution (by executing msbuild from the command prompt), I get the following error for the Nuget package build task:
"C:\git\repo\dirs.proj" (default target) (1:7) ->
"C:\git\repo\sources\dirs.proj" (default target) (2:5) ->
"C:\git\repo\sources\dev\Sdk\CompanyName.ProductName.Extensions.csproj" (default target) (7:6) ->
(GenerateNuspec target) ->
C:\Program Files\dotnet\sdk\5.0.408\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : Could not find a part of the path 'C:\git\ess\target\distrib\Debug\Amd64\CompanyName.ProductName.Extensions'. [C:\git\ess\sources\dev\Sdk\CompanyName.ProductName.Extensions.csproj]
Here is the CSPROJ file I have for this project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>CompanyName.ProductName.Extensions</AssemblyName>
<RootNamespace>CompanyName.ProductName.Extensions</RootNamespace>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeCoreAssets</TargetsForTfmSpecificBuildOutput>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<NuspecFile>CompanyName.ProductName.Extensions.nuspec</NuspecFile>
<PackageOutputPath>$(DistribRoot)\$(Configuration)\$(Platform)\$(MSBuildProjectName)</PackageOutputPath>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SkipAssemblyComVisible>true</SkipAssemblyComVisible>
<IncludeBuildOutput>false</IncludeBuildOutput>
<OutputPath>$(DistribRoot)\$(Configuration)\$(Platform)\$(MSBuildProjectName)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<NuspecBasePath>$(OutputPath)</NuspecBasePath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Core\CompanyName.ProductName.Core.csproj" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<Target DependsOnTargets="ResolveReferences" Name="IncludeCoreAssets">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
I personally think the issue is that for some reason when MSbuild is trying to create the Nuget package, it's trying to find the Extensions project DLLs in this path: \target\distrib\Debug\Amd64\CompanyName.ProductName.Extensions\, even though it actually built and stored the said binaries in this path earlier: \target\distrib\CompanyName.ProductName.Extensions\. <--- This is something I checked manually myself by examining the 'target' folder after running msbuild.
Visual Studio however doesn't have this issue. When I build this solution within Visual Studio, it stores the binaries for this Extensions project in \target\distrib\Debug\AnyCPU\CompanyName.ProductName.Extensions\ folder, which I think matches the pattern defined in the CSPROJ file:
<OutputPath>$(DistribRoot)\$(Configuration)\$(Platform)\$(MSBuildProjectName)</OutputPath>
Visual Studio also stored the Nuget package in this folder, which is also correct as per the <PackageOutputPath> spec mentioned in the CSPROJ file.
So can someone suggest why MSbuild is storing the built DLLs of this project in \target\distrib\CompanyName.ProductName.Extensions\, but is trying to find them in \target\distrib\Debug\Amd64\CompanyName.ProductName.Extensions\ ?
I think the issue is that for some reason, MSbuild isn't adhering to the <OutputPath> spec mentioned above when it's storing the built DLLs for this project.
I have been working through an awesome tutorial within Udemy to learn more about Blazor (https://www.udemy.com/course/programming-in-blazor-aspnet-core/), but have hit a stumbling block that I'm not entirely sure what to do with.
Short Version
When upgrading to .Net 5 from .Net Standard 2.1, I end up with this error when trying to run this sample Blazor application as soon as it loads up (so it's not hitting any of my code): System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') I see a similar problem with this SO link, but it didn't really give me much to go off of.
Detailed Version
With prior versions of .Net, you installed the latest, then Visual Studio picked that up, you switched projects and away you went - everything was seamless and just worked. With some of the newer stuff though, Microsoft's messaging has been extremely confusing and the problem I'm hitting now is inside that Udemy tutorial I need to utilize the IJSObjectReference interface to do something. When I first added that to the code, the type reference couldn't be resolved so a quick search pointed me to needing to move the project to .Net 5 by changing this:
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
to this (because Visual Studio doesn't always show .Net 5 as an option):
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
Seemed simple enough, so I changed the Client Blazor project to this and tried to compile. That gives me this error: Project BlazorMovies.Client is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project BlazorMovies.Client supports: net5.0 (.NETCoreApp,Version=v5.0). I figured okay, I'll bump Server to 5.0 next and then everything compiles fine, but as soon as I pull it up, I get this error: System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'). Then I remembered not recalling if I'd installed .Net 5 yet, so I went to check and (via learn.microsoft.com) I only have 4.8.03752 installed. I then did some searches to try and find the .Net installers and there were multiple (see here) - even the layout of the page is really overwhelming, with ~20 install links scattered throughout. I knew I needed at least x64, so I first installed the SDK since it said Visual Studio support and that went significantly faster than I expected (based on prior installs of .Net), but now VS is showing .Net 5 which seemed promising! I re-checked the registry though, and it still says 4.8.03752 and when I went to Add/Remove programs, .Net 5 doesn't show up like all the other versions. I next installed the Hosting Bundle which said it was successful, but the sample app still has the exact same error.
Any advice? I know Blazor is quite new, but with Microsoft's extremely confusing messaging between .Net Framework, .Net Standard, .Net Core and now a migration back into .Net 5 that seems to need multiple installers, I don't really know where to go next. That error is entirely generated from within the Web Assembly code according to the stack trace, so it doesn't appear to be anything related to what I'm doing. Here's a screenshot of everything Chrome shows me in the console:
To migrate Blazor Webassembly Application from netstandard2.1 to .NET 5, you could refer the following steps:
Install or update Visual Studio 2019 to version 16.8.0+, and install the .NET 5 SDK.
Change the Blazor Webassembly project setting.
Create a Blazor Webassembly project (When create the application, select .net core 3.1, then, the TargetFrameWork will be .netstandard2.1), Open the application .csproj file:
Update the SDK from Microsoft.NET.Sdk.Web to Microsoft.NET.Sdk.BlazorWebAssembly
Set the TargetFramework to net5.0
In case you have it, remove the package reference to Microsoft.AspNetCore.Components.WebAssembly.Build.
After updating, the .csproj file content as below:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
</ItemGroup>
</Project>
Update the Nuget dependencies version.
The result like this:
Then, the final .csproj file content looks as below:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.2" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>
</Project>
Clean the entire solution, otherwise the build engine won’t be able to re-generate all the required files with the updated framework.
Then running the application, the website works well.
Have you changed the header node in the *.csproj too?
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
...
</Project>
I've created a WPF application using VisualStudio 2017 by selecting the .Net framework 4.6. Know I'm trying to configure it for .Net Core 3.0 for WPF. But unfortunately, after changing my configuration, When reloading my projects, I got this error.
Project file is incomplete. Expected imports are missing.
I've checked all the reference files are there.
Here is my .csproj file.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>HelloWorld</AssemblyName>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Include="..\WpfApp\App.xaml" Link="App.xaml" />
<Compile Include="..\WpfApp\App.xaml.cs" Link="App.xaml.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="..\WpfApp\MainWindow.xaml" Link="MainWindow.xaml" />
<Compile Include="..\WpfApp\MainWindow.xaml.cs" Link="MainWindow.xaml.cs" />
</ItemGroup>
</Project>
I've installed this SDK version 3.0.100-preview5-011568. I've also enabled the Use previews of .Net Core SDK in VisualStudio.
You should upgrade to Visual Studio 2019. It includes a project template for WPF and Windows Forms applications targeting .NET Core 3.
From the docs:
Visual Studio 2017 doesn't support .NET Core 3.0 projects.
I want to install .NEt Framework using bootstrapper/Clickonce application. The code I have used is as shown below -
But it fails with this error -
warning MSB3155: Item 'Microsoft.Net.Framework.4.7.1' could not be located in 'D:\a\1\s\src\ABC\Main'.
Error MSB3147: Could not find required file 'setup.bin' in 'D:\a\1\s\src\ABC\Main\Engine'.
What I want to do is to install .net framework from vendor site and hence the installers are not bundled. Can someone help here ?
<Target Name="BuildBootstrapper">
<ItemGroup>
<BootstrapperFile Include="Microsoft.Net.Framework.4.7.1">
<ProductName>.NET Framework 4.7.1</ProductName>
</BootstrapperFile>
</ItemGroup>
<GenerateBootstrapper
ApplicationFile="ABC.application"
ApplicationName="ABC"
BootstrapperItems="#(BootstrapperFile)"
ComponentsLocation="HomeSite"
/>
</Target>
I am using VS2017
This worked fine for me where it creates setup.exe at the outputpath and redirects user if they dont have framework installed .
<Target Name="BuildBootstrapper">
<PropertyGroup>
<MyPathToPrerequisitePackages>C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper</MyPathToPrerequisitePackages>
<MyDesiredOutputPath>C:\Bootstrapper</MyDesiredOutputPath>
</PropertyGroup>
<ItemGroup>
<BootstrapperFile Include=".NETFramework,Version=v4.7.1">
<ProductName>Microsoft .NET Framework 4.7.1</ProductName>
</BootstrapperFile>
</ItemGroup>
<GenerateBootstrapper
ApplicationFile="ABC.application"
ApplicationName="ABC"
ApplicationUrl=""
BootstrapperItems="#(BootstrapperFile)"
ComponentsLocation="HomeSite"
Path="$(MyPathToPrerequisitePackages)"
OutputPath=""
/>
I'm not sure how to set the default nuget feed for my .net core project in Visual Studio Code to https://api.nuget.org/v3/index.json
When I attempt to add a package (and subsequently, restore dependencies), I get the following errors...
C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Unable to load the service index for source https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json. [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj]
C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj]
This source https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json has nothing to do with my current project, however it is used for other projects that are typically run using full blown Visual Studio. Those projects are saved in a completely different place to this project.
I simply want to be able to add nuget packages from nuget.org in my .net core project. How do I do this in VS code?
I don't currently have a nuget.config file in this project.
The package source mentioned in the error appears to be coming from a package source I have setup whilst using Visual Studio
This is my csproj file...
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1"/>
<PackageReference Include="CloudinaryDotNet" Version="1.3.1"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final"/>
</ItemGroup>
</Project>
CloudinaryDotNet is the package that generated the errors above.
I think VS Code is just running a dotnet restore, and the reason you're seeing this source being used is because it's configured in your User/Computer nuget configuration file (located on windows, which you seem to be running, at %appdata%\NuGet\NuGet.Config & %ProgramFiles(x86)%\NuGet\Config respectively). The VS configuration editor you showed is just a nice GUI for this configuration file.
If you want to keep this general setting, you should be able to use a nuget.config file in your VS Code project (which you mentioned you don't have at the moment). There is more info on this here -Add custom package source to Visual Studio Code.
Also, if you're trying to restore manually, you can use one of these 2 flags -
dotnet restore --source https://api.nuget.org/v3/index.json
dotnet restore --ignore-failed-sources
These are pretty self explanatory, but you can see the full documentation here - https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x
Hope this helps (: