question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loaded .csproj project is not refreshed when 'dotnet restore' is executed

See original GitHub issue

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview4-004233)

Product Information: Version: 1.0.0-preview4-004233 Commit SHA-1 hash: 8cec61c6f7

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.0-preview4-004233

VS Code version: 1.8.1 C# Extension version: 1.6.2

Steps to reproduce

Run… dotnet new Add to csproj:

<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />

Add to program.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;

Total text of csproj is (I also updated the .NET versions to Core 1.1.0):

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
  </ItemGroup>

</Project>

Total text of program.cs:

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;

public class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        app.Run(
            context => { 
                return context.Response.WriteAsync("Hello Scott");
             }
        );
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

Expected behavior

Omnisharp should be able to identify new packages and treat them the same as references in the old json version of the config.

Actual behavior

AspNetCore in each using statement has a red underline with message “namespace does not exist”. Once adding classes such as IApplicationBuilder or WebHostBuilder to the code, they will not be recognized either. However, the syntax is correct, as demonstrated by being able to run dotnet run

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DustinCampbellcommented, Jan 31, 2017

Yes, I totally agree. The two issues are related though.

0reactions
DustinCampbellcommented, Feb 3, 2017

That is, I have a fix for the issue where the project doesn’t update its references after a dotnet restore until you restart.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet restore getting error with new csproj file, no project.json ...
I ran into this on my Mac too. The problem is that the Yeoman generator (generator-aspnet) has already been upgraded to use the...
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
Select the Tools > NuGet Package Manager > Package Manager Settings menu command. · Set both options under Package Restore. · Select OK....
Read more >
dotnet restore command - .NET CLI | Microsoft Learn
The dotnet restore command uses NuGet to restore dependencies as well as project-specific tools that are specified in the project file.
Read more >
NETSDK1004: Assets file not found - .NET CLI | Microsoft Learn
A change to the project file wasn't automatically detected and restored by the project system. To resolve the error, open a command prompt...
Read more >
PackageReference in project files - NuGet - Microsoft Learn
(See For more details NuGet pack and restore as MSBuild targets.) Project type support. By default, PackageReference is used for .NET Core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found