doumuyu0837 2019-05-06 04:11
浏览 63

限制VS Code for Go仅下载v 1.11版的软件包

I am using Visual Studio Code version 1.33.1 as IDE for our Go applications. We would like to use Go version 1.11 for our applications. However looks like one or more of the dependencies we are using has downloaded a package for Go 1.12. Now, VS Code is failing to build the application with the following error:

go build golang.org/x/sys/unix: module requires Go 1.12 go build github.com/pelletier/go-toml: module requires Go 1.12 go [1,1]

I tried re-installing Go 1.11, removed the offending packages and let it reinstall. No matter when I tried to build VS Code is downloading the 1.12 version fails to build. I would like VS Code not to download 1.12 version of the packages and restrict it to 1.11 only.

  • 写回答

1条回答 默认 最新

  • dongping4901 2019-05-06 05:05
    关注

    Go 1.12 Release Notes (February 2019)

    Modules

    The go directive in a go.mod file now indicates the version of the language used by the files within that module. It will be set to the current release (go 1.12) if no existing version is present. If the go directive for a module specifies a version newer than the toolchain in use, the go command will attempt to build the packages regardless, and will note the mismatch only if that build fails.

    This changed use of the go directive means that if you use Go 1.12 to build a module, thus recording go 1.12 in the go.mod file, you will get an error when attempting to build the same module with Go 1.11 through Go 1.11.3. Go 1.11.4 or later will work fine, as will releases older than Go 1.11. If you must use Go 1.11 through 1.11.3, you can avoid the problem by setting the language version to 1.11, using the Go 1.12 go tool, via go mod edit -go=1.11.


    $ go help go.mod
    
    The go.mod file itself is line-oriented, with // comments but
    no /* */ comments. Each line holds a single directive, made up of a
    verb followed by arguments. For example:
    
      module my/thing
      go 1.12
      require other/thing v1.0.2
      require new/thing/v2 v2.3.4
      exclude old/thing v1.2.3
      replace bad/thing v1.4.5 => good/thing v1.4.5
    
    The verbs are
      module, to define the module path;
      go, to set the expected language version;
      require, to require a particular module at a given version or later;
      exclude, to exclude a particular module version from use; and
      replace, to replace a module version with a different module version.
    

    A possible solution to your problem was first introduced in Go1.12: the go.mod verb go, to set the expected language version.


    UPDATE:


    Comment: I tried using the suggested command: go mod edit -go=1.11 I got an error: flag provided but not defined: -go I manually edited to add go 1.11 right under my module declaration in all go.mod files, it did not work. – user2995358

    Your results are expected. As I explained before and the documentation states, the go.mod verb go was first introduced in Go1.12.

    For example, the expected results,

    $ go version
    go version go1.11.10 linux/amd64
    $ go mod edit -go=1.11
    flag provided but not defined: -go
    usage: go mod edit [editing flags] [go.mod]
    Run 'go help mod edit' for details.
    $ 
    
    $ go version
    go version go1.12.5 linux/amd64
    $ go mod edit -go=1.11
    $ 
    

    Read the documentation:

    $ go version
    go version go1.11.10 linux/amd64
    $ go1.11 help modules
    
    Preliminary module support
    
    Go 1.11 includes preliminary support for Go modules,
    including a new module-aware 'go get' command.
    We intend to keep revising this support, while preserving compatibility,
    until it can be declared official (no longer preliminary),
    and then at a later point we may remove support for work
    in GOPATH and the old 'go get' command.
    $ 
    
    
    $ go version
    go version devel +004fb5cb8d Fri May 3 03:49:11 2019 +0000 linux/amd64
    $ go help modules
    
    Module support
    
    Go 1.13 includes official support for Go modules,
    including a module-aware 'go get' command.
    Module-aware mode is active by default.
    $
    

    Go 1.11 includes only preliminary support for Go modules. Go 1.13 includes full official support for Go modules.

    Why do you expect everything to work flawlessly in Go1.11 with only preliminary support?

    评论

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并