Unable to Create .go File Within IntelliJ IDEA - windows

I'm using Intellij IDEA Community 2016.3 with the golang plugin.
Recently within Intellij I created a new package then I tried to create a new go file in that package. Intellij gave me a template error message, something like this:
Unable to parse template "Class" Error message: This template did not produce a Java class or an interface - during New -> Java Class
(To create the file I right-clicked the package and selected New > Go File.)
I then went into the file system and manually created the file. After a brief pause, Intellij closed the pane on the left that lists all my packages. Intellij also corrupted the project such that I was not able to view the project pane again.
I recreated the project and everything seems to be fine now but I don't want to have to do all that again each time I create a .go file.
I don't know if this makes a difference, but the package I tried creating the file in is a download from github. Intellij has been telling me this:
The directory C:\go-workspace\src\gopl.io is under Git, but is not registered in the Settings.
It's someone else's project -- files for learning go-- and I don't plan on sending any pull requests. I simply created the package and file there because they are part of learning go.
How do I create .go files in Intellij?
Added 21-Jan:
Here are my project settings:

Make sure you got the Go setup properly before continuing.
Next I'd also make sure the plugin setup is good(maybe reinstall after making sure your go setup is ok), such as the project SDK is set to something Go and not Java as that's usually the default(see image below) and IntelliJ can detect your GOPATH.
If the project your'e working on was not an IntelliJ module before and you just opened it, make sure the .iml file is a Golang module (IntelliJ usually asks you to do this automatically if it's not already done, but you need to setup the project SDK to Go first I assume)
ie.(my hello.iml);
<?xml version="1.0" encoding="UTF-8"?>
<module type="GO_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="GOPATH <hello>" level="project" />
</component>
</module>
Here is a comprehensive step by step guide for a starter setup;
https://rootpd.com/2016/02/04/setting-up-intellij-idea-for-your-first-golang-project/

Related

IntelliJ: Invalid .iml location and content when I choose "create new project" over "open existing project"

I have several question about how the project structure is created and stored. Here is the context: I have a git repository containing some groovy files which I use for a Jenkins library. So what is interesting us here is the "src" folder, which contains groovy classes, and the "vars" folder, which contains groovy scripts (DSL).
There's no existing IntelliJ project, no .idea folder, no .iml, no pom.xml ...
Let's say that the repository is located under:
C:\Toto\JenkinsLibrary
- .git
- src
- vars
My objective is to create a Maven project from scratch.
First Method:
Initially, I open IntelliJ and choose "Create new project". Select "Maven", no archetype, then I enter the following information:
Project name: I leave the project corresponding to the artifactID: JenkinsBuildLibrary
Project location: C:\Toto\JenkinsLibrary
More settings: Module name = JenkinsLibrary, Content root = Module file location = C:\Toto\JenkinsLibrary, Project format = .idea
Then click finish
Here, the .iml file is generated OUTSIDE the .idea folder, looking like this:
C:\Toto\JenkinsLibrary
- .git
- .idea
- src
- vars
- JenkinsLibrary.iml
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Then soon after the content of the iml goes to:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
Also, I have been trying to reproduce this several times and it is extremely complex to get a consistent behavior, sometimes I have the iml file with no generated pom, sometimes I have the pom with no iml .... so I guess there's a huge bug here.
Finally, if I change the project structure by adding other sources folder or other modules, nothing changes in my .iml file. Then I can close IntelliJ, remove ALL .idea, .iml and pom.xml files ... to get everything back once I reopen IntelliJ, leaving me to wonder: where is that configuration actually stored ?!
Second method:
This time, I choose "Open existing project". I select the folder: C:\Toto\JenkinsLibrary
There's no existing project but it still works and create a new project.
The .iml file is now under the .idea project !!
C:\Toto\JenkinsLibrary
- .git
- .idea
- JenkinsLibrary.iml
- src
- vars
- pom.xml
Right click the module, select "Add Framework Support", Maven, and I get a pom file.
When I change the project structure, the .iml is correctly updated. Exemple:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$/../../tools/ToolJenkins/src">
<sourceFolder url="file://$MODULE_DIR$/../../tools/ToolJenkins/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Now If I close IntelliJ, remove ALL .idea, .iml and pom.xml files ... I don't get anything back once I reopen the project (only the files and folder located under the module), which seems a far better behavior !
SHORT SUMMARY:
When creating a new Maven project, the .iml is located at the root of the project instead of under the .idea folder and is invalid. The project structure seems to be stored elsewhere. I have no way to ship a valid project to my teammates.
When opening a new project, the .iml is located under the .idea folder and is valid. The project structure is stored under it (with warnings that project are defined by a pom file and changes performed under the Project structure menu could be wiped). I can ship a valid project to my teammates.
I need to understand those differences and how IntelliJ works. I hope for a quick answer since this is not the first time we struggle with project structures and may well move back to another, more stable IDE is necessary.
Thanks !
IntelliJ IDEA stores generated project files externally for Maven or Gradle based projects. You should never edit them manually or adjust any content roots and source roots via the interface as they are managed by the build system configuration (pom.xml) in your case.
To change or add additional source roots you need to modify pom.xml directly.
It looks like your directory layout doesn't follow the standard Maven convention. You may need to override it or add additional directories.

Unable to step into Nuget package

I have a common project that I build and create a nuget package from, for consumption in my other applications.
The build process for the common project both creates a nuget package, deploys it to our private nuget repo and pushes the symbols to our internal symbol server.
In my "other applications", in this specific case an ASP.NET website, I pull in the nuget package from our repo but when I try to step into code in that assembly it just skips over it. I cleared my local symbol cache and as soon as I start debugging VS pulls in all the symbols from the symbol server so I know that bit is working.
Can anyone help me?
You need to publish Nuget package with symbols and refer to them using the Symbols under Tools->Options->Debugging->Symbols.
See HOW TO DEBUG A .NET CORE NUGET PACKAGE?
Other members also asked the similar issue before:
How to debug code in a nuget package created by me
Update:
Since you want to step into code in the assembly, you still need to provide the source code file in the NuGet package alongside the dll.
As we know:
A symbol is a file containing metadata that represent the link between
your original source code and the machine code that has been
translated by a compiler.
In the Microsoft world, a symbol is represented by a .PDB (Program DataBase) file. It is the heart of the debugging process because thanks to these metadata, the debugging tools are able to correlate the instructions executing in the application to the original source code and providing features like breakpoint or variable watchers.
So if you only provide the dll and .pdb file, you still not step into the code, you also need provide the source code, then add the source code to the Debug Source Files for the solution that references the package:
More detail on providing the source code:
If you're currently packaging without a Nuspec, you'll need to create a Nuspec, then add the pdb to the list of files in the lib folder and source file in the src folder. "NuGet spec" may be a useful command for generating the initial spec as defined in NuGet docs. Below is my .nuspec file, you can check it:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyTestPackage</id>
<version>1.0.3</version>
<authors>Admin</authors>
<owners>Admin</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="bin\Debug\MyTestPackage.dll" target="lib\Net46" />
<file src="bin\Debug\MyTestPackage.pdb" target="lib\Net46" />
<file src="Class1.cs" target="src" />
</files>
</package>
More detail on add the source code to the Debug Source Files:
When you have a solution open, right click on Solution, select Properties...Common Properties...Debug Source Files, and add the root source directory for the relevant binary reference:

Task for a Bamboo Build plan fails when trying to get information from packages

I am trying to run an MSBuild task in atlassian bamboo for a test run of a Bamboo plan on my local device. I have created the plan and it will retrieve the code from Github successfully, as well as being successfully running the default scoure control checkout.
The first problem I have is that the system will fail because the MSBuild task cannot get the referenced files. So when I looked into the Manage Nuget Packages, It says some of the packages are missing, and when I click Restore most of them restore but some of them have errors.
I think the main reason is because of this package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.0 is not being installed correctly. The error message says that it is because the path, file name or both are too long, but I have not named anything the project is already build and running successfully from Github. I have tried to install as well by using the Package Manager Console but I get the same result. I also tried creating the folders that it said the file was meant to be located but this is not working either.
I think that the problem is that the package is not found during package restore so I tried to add a NuGet.config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>
But this is not working how can I fix this?
According to the error message screenshot, the mentioned package "Carfinance.Authorization.Core.Mvc" is not found in nuget.org site. Please make sure this package's source URL has added into your Visual Studio NuGet Package Manager Source list (Tools -> Options -> NuGet Package Manager -> Package sources).
And please add the node in the global NuGet.Config file which stored in C:\Users\UserName\AppData\Roaming\NuGet folder. After change the config file, please remember restarting your Visual Studio.
For the Microsoft.CodeDom.Providers.DotNetCompilerPlatform path too long issue, please make sure the stored path folder is not too long. You could create a new project and store it on desktop and install this packages to check whether it could be install correctly. Then please copy your current project on desktop too, it could make sure its stored path will not too long.

Is it possible to get NuGet.exe running disconnected from Visual Studio?

I've been wrestling with NuGet for a few days now and I'm turning to StackOverflow in frustration - hopefully someone here can be kind enough to point me in the right direction.
I've used NuGet several times for simple one-man pet projects, but this is the first time I've used it for something I really care about and want to have fully continuous builds, etc. I'm trying to create a simple NAnt build script to get the source for Git, ensure the external dependencies have been brought down, compile, and run tests - vanilla CI.
I originally went down the path of trying to get solution restore working, but it just didn't work or I didn't how it worked. Visual Studio is not on the build server and will not be installed there - that is not an option. As an aside, I couldn't get solution restore to work just with two developers (one trying to bring down the source fresh and build cleanly). I'm assuming it's because "allow solution restore" must be turned on everywhere (and is not by default). I punted on that approach before I got to the bottom of it - frankly, having my package manager so tightly coupled to the IDE makes me uncomfortable and was hoping I could do it another way. The package managers I'm used to using are simple command line tools - the CI build script invokes it on build, and developers do it on demand. I've spent the last two hours trying to get this working with the last 30 minutes in the NuGet source code. I feel like I'm fighting the tool and need to reboot.
Does anyone have any examples of the best to use NuGet in a multi-developer + CI scenario? This is what I want:
Any and all developers can get the source and run the tests in 3 or
less clicks (preferably 1). If the binaries are not present locally, that will be JIT fetched. If they are there, they will be updated if necessary, etc. This would ideally not even require NuGet to be installed (i.e. NuGet.exe would need to be in my repo).
Do #1 via a CI server like Jenkins, TeamCity, etc. (preferably using the same script)
If its not overly fighting the tool, I would like to have all this disconnected from Visual Studio with a single packages.config file and all binaries dumped into a single Lib folder in the root of the repo.
Any pointers would be very much appreciated.
Below, how I think you can achieve each your requisites:
You need to "Enable NuGet Package Restore" in your solution: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
As #alexander-doroshenko mentioned for TeamCity you can use Nuget Installer: http://confluence.jetbrains.com/display/TCD7/NuGet+Installer, but if you want a script to run in Jenkins, try this (works at TC too, as a command line step) for each project:
nuget.exe install "[Project folder]/packages.config" -source "" -solutionDir "" -OutputDirectory "packages"
This requisite will be done by item 1 and 2.
TeamCity has a build step for that, called "NuGet Installer", it fetch required packages from .sln file and download the locally. It does not require Visual Studio to run.
Read more about it here: http://confluence.jetbrains.com/display/TCD7/NuGet+Installer
There are several different solutions for integrating NuGet into your build process depending on how much integration you require. In our case we wanted to use NuGet as package manager and allow developers to build their solutions even if they haven't got NuGet installed on their machine. For that to work we enabled package restore which adds the NuGet binaries to your solution folder and updates the project files. Note that NuGet doesn't always do the update of the project files correctly. In our case we found that some project files got updated but others didn't. To verify that the project was updated you will need to open the project file as XML file. To achieve this load the solution and right click the project in question and select unload project. Then right click the project again and select edit [PROJECT_NAME]. In the project file you should see
A RestorePackages property in the first propertygroup. This property should have the value true
An import statement at the very end of the project file. This import statement should point to the 'NuGet.targets file that accompanies the NuGet binary.
Below is an example of one of our project files (heavily edited)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>
<ProjectGuid>{8B467882-7574-41B2-B3A8-2F34DA84BE82}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>MyCompany.MyNamespace</RootNamespace>
<AssemblyName>MyCompany.MyNamespace</AssemblyName>
<!-- Allow NuGet to restore the packages if they are missing -->
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<Import Project="$(SolutionDir)\BaseConfiguration.targets" />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<!--
.... MANY MORE FILES HERE
-->
</ItemGroup>
<!-- Import the Nuget.targets file which integrates NuGet in the build process -->
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
The next step you'll need to take is to provide a solution level NuGet configuration file in which you'll indicate where the packages need to be 'installed' and what the URL of the package repository is. In our case the solution directory structure looks like:
(D) root
(D) build
(D) packages
(D) source
(D) .nuget
NuGet.config
NuGet.exe
NuGet.targets
(D) MyCoolProject
MyCoolProject.csproj
MyCoolProject.sln
(D) templates
NuGet.Config
Where (D) indicates a directory.
The NuGet.config file contains the following configuration settings.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<config>
<add key="repositorypath" value="packages" />
</config>
<packageSources>
<add key="OurPackageServer" value="PACKAGE_SERVER_ADDRESS" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
This configuration file indicates that package restore is enabled, that the repository path (where the packages are placed) is the packages directory and which package sources are active.
By placing a NuGet.config file in the root directory we can use the hierarchical configuration option with NuGet. This allows the individual solutions to override computer specific configurations. The other benefit is that this way we don't need to have NuGet installed on the build server (because the executable and the configurations are in the repository).
With this setup developers can build the solution from Visual Studio. The build should work fine on developers machines even if they don't have NuGet installed. Note however that they won't be able to add packages to a project without having NuGet installed in visual studio.
On the build server you can simply use MsBuild to build the solution which will automatically download the packages from your package repository. Visual Studio is not required to be installed on the build machine for that (just the .NET framework of your choice).

Custom nuget feed, VS doesn't see package as installed

Hi all
I have a local Nuget source with a package containing some default items I want in my projects (default corporate models and styles and some default pages). It is only copying items in to the project and adding a connection string to the web.config, nothing fancy.
I can install the package via the Package Manager Console and the GUI. However, it never shows as installed. This means that I cannot update it nor can I uninstall it. If I go to the GUI, it shows the package as not installed, even though it has added all items to the project and has a folder for the package in the packages directory.
Also, I want to use this NuGet package to overwrite some files that already exist in the default MVC project (such as AccountController and LogonUserControl.ascx). Can this be done or will I need to start off with the blank MVC template instead of the default?
Packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MyCompanyMVC" version="1.1" />
</packages>
NuGet won't overwrite files - I don't believe there's a way to force it, however you could probably "work around" this by using a PowerShell script (tools/install.ps1) to delete the old file and rename your injected file to have the required name.

Resources