I am currently attempting write an application that will function as an automatic publishing process. In the process, I need to build, and publish a number of items. I am able to build, and publish the web application successfully, however, when publishing the website, I am running into problems.
I am able to successfully complete the required with the following command line execution:
msbuild website.publishproj /p:deployOnbuild=true /p:PublishProfile="test.pubxml"
I am trying to execute this by using the build libraries, but it is failing:
string projectFileNamepub = CurrentPublish.ExcaliburBuildPath;
Dictionary<string, string> GlobalPropertypub = new Dictionary<string, string>();
ProjectCollection pcpub = new ProjectCollection();
//pcpub.SkipEvaluation = true;
//GlobalPropertypub.Add("Configuration", "Release");
//GlobalPropertypub.Add("Platform", "x86");
GlobalPropertypub.Add("DeployOnBuild", "true");
GlobalPropertypub.Add("PublishProfile",CurrentPublish.ExcaliburPublishProfile);
//GlobalPropertypub.Add("VisualStudioVersion", "11.0");
BuildRequestData BuildRequestpub = new BuildRequestData(projectFileNamepub, GlobalPropertypub, null, new string[] { "Build" }, null);
BuildResult buildResultpub = BuildManager.DefaultBuildManager.Build(new BuildParameters(pcpub), BuildRequestpub);
if (buildResultpub.OverallResult == BuildResultCode.Success)
{
bsuccess = true;
txtOutput.Text = txtOutput.Text + "Publish Success \n";
}
The commented out properties are properties that I have attempted to use, but none of them were successful.
Is there something that I am doing wrong? I have used exactly this to publish another web application before this one, and it completes successfully.
This target completes successfully:
_CheckForInvalidConfigurationAndPlatform
It then fails on Build.
If you create your build parameters this way you can display the build output on the console:
var buildParameters = new BuildParameters(pc)
{
Loggers = new List<Microsoft.Build.Framework.ILogger> { new ConsoleLogger() }
};
When I did this I saw the following error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4353,5): error MSB4127: The "GetPublishingLocalizedString" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Web.Publishing.Tasks.GetPublishingLocalizedString' to type 'Microsoft.Build.Framework.ITask'.
I searched for error MSB4127 and found the answer here: MSBuild "GenerateFakes" Error MSB4127, MSB4060
I was already specifying the VisualStudioVersion. I simply added the <runtime> section from C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.config into my App.config and the build and publish worked.
Related
I am trying to get some net core 2.1 projects to build on a new build server that we have. We have installed Visual studio tools for 2017 and 2019.
I am getting this error when it tried to build it via our TFS build process. We use cake scripts to build the code.
C:\Program Files\dotnet\sdk\6.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')". [MSBuild]::GetTargetFrameworkIdentifier Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). [D:\Agents\EROS-006\_work\2\s\src\Cases.CommandHandlers\Cases.CommandHandlers.csproj]
Is it something to do with the csproj contents? We have this declared at the top as this bit of the message stands out
GetTargetFrameworkIdentifier Static method invocation should be of the form: $([FullTypeName]::Method())
The csproj version details:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.4</RuntimeFrameworkVersion>
<TargetLatestAspNetCoreRuntimePatch>True</TargetLatestAspNetCoreRuntimePatch>
</PropertyGroup>
...
I have searched for an answer but seem to point to mono related things, which we don't use at all, its a windows machine with the visual studio tools installed as mentioned above.
The cake build part looks like this
Task("Build")
.IsDependentOn("Version")
.Does(() =>
{
var settings = new DotNetCoreRestoreSettings()
{
Sources = packageSources
};
DotNetCoreRestore(settings);
if(useLatestMsBuild){
MSBuild(solution, new MSBuildSettings {
Configuration = configuration,
MaxCpuCount = maxcpucount,
ArgumentCustomization = args => args
.Append("/p:Version=" + versionInfo.InformationalVersion.Replace("/", "-"))
.Append("/p:AssemblyVersion=" + versionInfo.AssemblySemVer)
.Append("/p:FileVersion=" + versionInfo.AssemblySemVer)
});
}else{
MSBuild(solution, new MSBuildSettings {
Configuration = configuration,
MaxCpuCount = maxcpucount,
ToolVersion = MSBuildToolVersion.VS2017,
Restore = true,
ArgumentCustomization = args => args
.Append("/p:Version=" + versionInfo.InformationalVersion.Replace("/", "-"))
.Append("/p:AssemblyVersion=" + versionInfo.AssemblySemVer)
.Append("/p:FileVersion=" + versionInfo.AssemblySemVer)
});
}
});
Looking at further build steps in cake and powershell there was mention of it compiling with mono instead of the default. Updating cake to version 2.0 and rewiting it from the ground up seems to resolve the issue.
Installing Visual Studio Build Tools 2022 and latest nuget.exe added to the environmental variable PATH seemed to help. Ideally installing everything that the build server has on it and running the same scripts locally helped a lot.
I try to add additional information to the output console or log file in TFS2018 from a called method, because of broken unit test only on the build server and too less information about exception.
Let's say we have a method (in this example properties):
public GsModule GdiModule
{
get
{
if (_gdiModule == null)
{
string directory = (new FileInfo(typeof(GsModule).Assembly.Location)).DirectoryName;
string path = Path.Combine(directory, "WinGDI.txv");
_gdiModule = (GsModule) SystemObjects.DynamicLinker.LoadModule(path, false, true);
}
return _gdiModule;
}
}
I would like to get information about the path and directory from this method in output in Visual Studio Test Task in Team Foundation Server 2018.
I tried with:
Trace.WriteLine($"GDI directory: {directory}"));
and NUinit.Framework
TestContext.WriteLine($"GDI directory: {directory}"));
but without success.
PS: The build is configurated to x64 | Release and <DefineConstants>TRACE</DefineConstants>
Do you have any idea how can I get this kind of information?
I am getting Roslyn diagnostics errors when parsing a very basic .NET 4.6 application. The solution files can be downloaded from there
https://github.com/dotnet/roslyn/files/2393288/DemoSolution.zip
The dependency tree looks like this:
BLL -> DB
I am getting the following diagnostics errors in the BLL project:
The solution and projects build fine, still Roslyn gives these errors. Maybe the errors are misleading and I need to configure the projects in someway? Any idea how I can resolve these errors?
Here is the code used for parsing the files:
var properties = new Dictionary<string, string>
{
["DesignTimeBuild"] = "true",
["CheckForSystemRuntimeDependency"] = "true"
};
var workspace = MSBuildWorkspace.Create(properties);
workspace.WorkspaceFailed += (sender, args) =>
{
};
workspace.LoadMetadataForReferencedProjects = true;
Solution solution = workspace.OpenSolutionAsync(SolutionFilePath).Result;
foreach (var p in solution.Projects)
{
foreach (var file in p.Documents)
{
var semanticModel = file.GetSemanticModelAsync().Result;
var mscorlib = MetadataReference.CreateFromFile(file.FilePath);
var compilation = CSharpCompilation.Create("MyCompilation",
new[] { semanticModel.SyntaxTree }, new[] { mscorlib });
var model = compilation.GetSemanticModel(semanticModel.SyntaxTree);
var declarationDiagnistics = model.Compilation.GetDeclarationDiagnostics(CancellationToken.None);
var parseDiagnostics = model.Compilation.GetParseDiagnostics(CancellationToken.None);
var allDiagnostics = model.Compilation.GetDiagnostics(CancellationToken.None);
var methodBodyDiagnostics = model.Compilation.GetMethodBodyDiagnostics(CancellationToken.None);
}
}
Subscriping to the workspace.workspaceFailed event results in the following error:
Msbuild failed when processing the file 'MYPATH\BLL.csproj' with
message: C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets:
(1656, 5): The "GetReferenceNearestTargetFrameworkTask" task could not
be instantiated from the assembly "C:\Program Files (x86)\Microsoft
Visual
Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll".
Please verify the task assembly has been built using the same version
of the Microsoft.Build.Framework assembly as the one installed on your
computer and that your host application is not missing a binding
redirect for Microsoft.Build.Framework. Unable to cast object of type
'NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask' to type
'Microsoft.Build.Framework.ITask'. C:\Program Files (x86)\Microsoft
Visual
Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets:
(1656, 5): The "GetReferenceNearestTargetFrameworkTask" task has been
declared or used incorrectly, or failed during construction. Check the
spelling of the task name and the assembly name.
So this finally solved it:
Added the microsoft.build redirects as suggested by #GeorgeAlexandria
http://github.com/Microsoft/msbuild/issues/2369#issuecomment-353674937
Cleared the Microsoft.Build.* from the output bin folder
Added the Microsoft.Build.Locator as a reference
Added the line MSBuildLocator.RegisterDefaults() above the workspace code.
Source:
https://github.com/dotnet/roslyn/issues/26029#issuecomment-380164421
I want to include Stanford CoreNLP in my Unity3D project. I included CoreNLP from Nuget and downloaded the NLP models from CoreNLP. Then I copied the NLP model folder into the project -> bin -> Debug folder.
The code looks like this:
var jarRoot = #"stanford-corenlp-3.9.1-models\";
const string text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.setProperty("sutime.binders", "0");
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);
var sentences = annotation.get(typeof(CoreAnnotations.SentencesAnnotation));
if (sentences == null)
{
return;
}
foreach (Annotation sentence in sentences as ArrayList)
{
System.Console.WriteLine(sentence);
}
After running, I only got some Error info
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
I searched SLF4J site however the solution only applies to Java project. How do I supposed to solve this in my C# project?
First, go to the Visual Studio (I have VS 2017). Then go to the Tools menu and select NuGet Package Manager->Package Manager Console. The Package Manager Console will appear. Type this command: Install-Package slf4j-NetCommonLogging -Version 1.7.5.4 and press Enter key. The VS will install slf4j-NetCommonLogging dll file for your project and it will run correctly without any errors or warnings. Enjoy.
I am trying to add some command line arguments to my application using CommandLineParser:
using CommandLine;
using System;
namespace ConsoleApplication1
{
class Options
{
[Option('s', "site", Required = true,
HelpText = "The site to connect to. Please include http://")]
public string sitename { get; set; }
[Option('l', "list", Required = true,
HelpText = "The list to connect to.")]
public string listname { get; set; }
}
class Program
{
static void Main(string[] args)
{
var options = new Options();
Parser.Default.ParseArguments(args, options);
Console.WriteLine(options.sitename);
Console.WriteLine("\n");
Console.WriteLine(options.listname);
}
}
}
However, when I try calling this from CMD:
test -s sitename -l listname
I am getting this error:
Unhandled Exception: System.IO.FieNotFoundEsxcepion: Could not load file or assembly 'CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeytoken=de6f01bd326f8c32', or one of its dependancies. The system cannot find the file specified. at ConsoleApplication1.Program.Main(String[] args)
I have installed the CommandLineParser package and I can see it in my references list. When I navigate to this folder: \\file\IT\SK\Visual Studio Projects\ConsoleApplication1\packages\CommandLineParser.1.9.71\lib\net40 I can see that there is a CommanLine.dll and a CommandLine.xml.
Can someone please explain to me what is going on here?
Update
I am able to run this with command lines in Visual Studio if I DISABLE ClickOnce Security settings, and it works fine. However, when I publish the application, this is automatically selected and the problem persists.
When debugging with command line arguments and ClickOnce Security enabled, args[] is null ...
It's a security feature. Your executable resides on the network and is not trusted to access other network resources.
I bet it works if you copy everything to a local folder.
Is the dll also in the bin output folder? If not, check the properties of the reference and check that "copy local" is true.