Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PaluMacil opened this issue Jan 10, 2017 · 10 comments
Closed
Assignees
Milestone

Comments

@PaluMacil
Copy link

PaluMacil commented Jan 10, 2017

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

@PaluMacil
Copy link
Author

I added the following and OmniSharp immediately began to be able to see the namespaces for AspNetCore. Deleting the bin and obj folders, exiting, and removing the new item group below did not cause the issue to return. I am more confused now that it's working than I was when it wasn't working.

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0-msbuild2-final" />
  </ItemGroup>

@PaluMacil
Copy link
Author

PaluMacil commented Jan 11, 2017

I added

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

and the extension method below wasn't recognized. I tried deleting bin and obj and restoring / running again to no avail. Once I exited and restarted VS Code, it stopped putting a red underline under the extension method.

app.UseStaticFiles();

It seems that this problem must be that Omnisharp is slow at noticing newly added extension methods which are extremely important to .Net Core.

@desol
Copy link

desol commented Jan 23, 2017

This happened for me as well with an almost identical situation.
Windows 7 instead of Windows 10.

@DustinCampbell
Copy link
Member

Note that there isn't any automatic package restore for VS Code with the new csproj .NET Core proejcts. You must run a dotnet restore in order to pull the references in. Then, you should get IntelliSense.

@DustinCampbell
Copy link
Member

The issue tracking that work is #770.

@PaluMacil
Copy link
Author

@DustinCampbell I am speaking about the plugin not recognizing that a package has been added. I use dotnet restore to add a package and then need to exit / reopen vscode for Omnisharp to realize it should expand its recognized namespaces. I shouldn't have top exit the IDE after running dotnet restore. That's pretty clunky.

@DustinCampbell
Copy link
Member

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

@PaluMacil
Copy link
Author

Ok, thanks. I was worried we had a disconnect. I will look forward to the completed MSBuild support (which has been pretty nice looking so far btw).

@DustinCampbell DustinCampbell added this to the 1.7 milestone Feb 3, 2017
@DustinCampbell DustinCampbell self-assigned this Feb 3, 2017
@DustinCampbell
Copy link
Member

OK. The issues aren't precisely related. I have a fix for this one.

@DustinCampbell
Copy link
Member

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

@DustinCampbell DustinCampbell changed the title .csproj project namespaces not recognized Loaded .csproj project is not refreshed when 'dotnet restore' is executed Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants