Giter VIP home page Giter VIP logo

Comments (12)

jmarolf avatar jmarolf commented on September 15, 2024

This means that the environment in which dotnet format is running in is configured such that it can't find where MSBuild is located. How did you install dotnet format on the machine?

from format.

jmarolf avatar jmarolf commented on September 15, 2024

format/src/Program.cs

Lines 79 to 81 in 3684ac0

// Since we are running as a dotnet tool we should be able to find an instance of
// MSBuild in a .NET Core SDK.
var msBuildInstance = Build.Locator.MSBuildLocator.QueryVisualStudioInstances().First();

from format.

JoeRobich avatar JoeRobich commented on September 15, 2024

@nnpcYvIVl Has you issue been resolved or can you share any more details about your installation and how you are running dotnet-format? Thanks!

from format.

nnpcYvIVl avatar nnpcYvIVl commented on September 15, 2024

@jmarolf @JoeRobich Sorry for the delay.

MSBuild was installed with Build Tools for Visual Studio 2017 and works without issue.

I installed dotnet-format with this command

dotnet tool install -g dotnet-format

Then I copied the "%userprofile%.dotnet\tools" folder to "%ProgramFiles(x86)%\dotnet-format".

From the command line I ran a batch file containing this command

"C:\Program Files (x86)\dotnet-format\dotnet-format.exe" --dry-run --workspace "C:\Users\User\ClassLibrary1\ClassLibrary1.sln" 1> "C:\Users\User\output.txt" 2>&1

It worked as expected and this was the output

Formatting code files in workspace 'C:\Users\User\ClassLibrary1\ClassLibrary1.sln'.
Formatting code files in project 'ClassLibrary1'.
Formatted code file 'Class1.cs'.
Format complete.

When I create a scheduled task using the same credentials and pointing to the same batch file I get the failure with the stacktrace posted above.

from format.

JoeRobich avatar JoeRobich commented on September 15, 2024

@nnpcYvIVl dotnet-format uses the MSBuild from the .NET Core SDK. Does the user that the scheduled task runs as have .NET Core installed?

from format.

nnpcYvIVl avatar nnpcYvIVl commented on September 15, 2024

@JoeRobich Thanks for the clarification on the MSBuild version.

.NET Core is installed for that user, here is the output of a couple of commands:

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.203
 Commit:    e5bab63eca

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.3.9600
 OS Platform: Windows
 RID:         win81-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.203\

Host (useful for support):
  Version: 2.2.4
  Commit:  f95848e524

.NET Core SDKs installed:
  2.2.203 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
dotnet tool list -g
Package Id         Version      Commands     
---------------------------------------------
dotnet-format      3.0.4        dotnet-format

from format.

JoeRobich avatar JoeRobich commented on September 15, 2024

@nnpcYvIVl Instead of moving dotnet-format out of the .dotnet/tools folder. Can you instead install dotnet-format as the user that the scheduled task runs as. I am not sure manually relocating dotnet global tools is supported.

from format.

elms avatar elms commented on September 15, 2024

Not directly related, but I received the same error when trying to run from a make file under msys2 (or cygwin). Here was my solution that I still want to try to improve. Basically I needed two additional paths in my search path: the install path %USERPROFILE%\.dotnet\tools (see) and C:\Program Files\dotnet

DOTNET_TOOLS = $(shell cygpath $(USERPROFILE)/.dotnet/tools)

format-check:
       PATH=$(PATH):/c/Program\ Files/dotnet:$(DOTNET_TOOLS) dotnet-format --check -v diagnostic -w $(SOLUTION)

from format.

jmarolf avatar jmarolf commented on September 15, 2024

If we want running from a non-sdk environment to work, I would recommend allowing users to specify an explicit path to msbuild.

from format.

JoeRobich avatar JoeRobich commented on September 15, 2024

dotnet-format is a dotnet tool designed to be installed and run by the dotnet CLI. We won't support other installation method at this time. dotnet CLI local tools are a newer concept that may work well for this scenario.

from format.

Loffe avatar Loffe commented on September 15, 2024

I ran into this issue as well, probably due to another installation method. The dotnet core SDK was missing, and the error message InvalidOperationException: Sequence contains no elements does not really give any clue of the real error.

Can this error message be improved to say something along the lines:
Could not find MSBuild, make sure .NET Core SDK is installed

from format.

JoeRobich avatar JoeRobich commented on September 15, 2024

@Loffe Thanks for the suggestion. It'll be in the next release.

from format.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.