I have all my views in a project inheriting from a ViewBase class that inherits from UserControl. In my XAML I reference it thus:
<f:ViewBase x:Class="Forte.UI.Modules.Configure.Views.AddNewEmployeeView"
xmlns:f="clr-namespace:Forte.UI.Modules.Configure.Views"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
It works fine.
Now I have moved the ViewBase to another project (so I can refernce it from multiple projects) so I reference it like:
<f:ViewBase x:Class="Forte.UI.Modules.Configure.Views.AddNewEmployeeView"
xmlns:f="clr-namespace:Forte.UI.Modules.Common.Views;assembly=Forte.UI.Modules.Common"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
This works fine when I run from the IDE but when I run the same sln from MSBuild it gives a warning:
"H:\dev\ExternalCopy\Code\UI\Modules\Configure\Forte.UI.Modules.Configure.csproj" (default target)
(10:12) ->
(ValidateXaml target) ->
H:\dev\ExternalCopy\Code\UI\Modules\Configure\Views\AddNewEmployee\AddNewEmployeeView.xaml(1,2,1,2): warning : The tag 'ViewBase' does not exist in XML namespace 'clr-namespace:Forte.UI.Modules.Common.Views;assembly=Forte.UI.Modules.Common'.
Then fails with:
"H:\dev\ExternalCopy\Code\UI\Modules\Configure\Forte.UI.Modules.Configure.csproj" (default target)
(10:12) ->
(ValidateXaml target) ->
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9):
error MSB4018: The "ValidateXaml" task failed unexpectedly.\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: at MS.MarkupCompiler.ValidationPass.ValidateXaml(String fileName, Assembly[] assemb
lies, Assembly callingAssembly, TaskLoggingHelper log, Boolean shouldThrow)\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute()\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute()\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: at Microsoft.Silverlight.Build.Tasks.ValidateXaml.Execute()\r
C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(210,9): er
ror MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engin
eProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)
Any ideas what might be causing this behaviour?
Using Silverlight 3
Here is a cut down version of the MSBuild file that fails to build the sln that builds fine in the IDE (sorry couldn't get it to format here):
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Compile">
<ItemGroup>
<ProjectToBuild Include="..\UI\Forte.UI.sln">
<Properties>Configuration=Debug</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="Compile">
<MSBuild Projects="#(ProjectToBuild)"></MSBuild>
</Target>
</Project>
Thanks for any help!
The only way, so far, I have found for getting around this is to refernce the actual assembly rather than the project. It's a bit hokey, anyone got a better idea?
Related
I want to use msbuild /restore with my project file. However, my project file is more like a script which orchestrates building multiple projects with particular properties, etc. Thus, it doesn’t make sense for me to set Sdk="Microsoft.NET.Sdk" because that causes weird errors to show up. However, if I don’t specify the Sdk, the /restore is ignored and it fails to actually restore anything.
Here is my example standalone project:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="RoslynCodeTaskFactory" Version="2.0.7" />
</ItemGroup>
<Target Name="Build">
<HelloWorld/>
</Target>
<UsingTask AssemblyFile="$(RoslynCodeTaskFactory)" Condition="'$(RoslynCodeTaskFactory)' != ''" TaskFactory="CodeTaskFactory" TaskName="HelloWorld">
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
Console.WriteLine("Hello, world!");
]]>
</Code>
</Task>
</UsingTask>
</Project>
My invocation and output:
C:\Users\binki\AppData\Local\Temp>"\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /restore helloworld.proj
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2018-05-15 01:23:28.
Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" on node 1 (default targets).
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files 9x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.
Done Building Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default target) (1:2) ->
(Build target) ->
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.71
I have a line of code that I got from a site called Zetcode, and in this to build the first example, I compile the code like this:
gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll 01-simple-cs-example.cs -out:simple-sample.exe
This builds the exe that draws my window, but I don't think my csproj file is correct.
<Project DefaultTargest="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- This Property will make a variable named MSBuildSample, then you can use it to
assign to whatever in the script.
Properties are variables inside the script.
-->
<SrcPath>src\</SrcPath>
<AssemblyName>01-simple-cs-example</AssemblyName>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<!-- This Compile statement, gathers all the source files listed in an item called Compiled
ItemGroups interact with the source code.
-->
<Compile Include="$(SrcPath)01-simple-cs-example.cs" />
</ItemGroup>
<!-- In the Build target, the Inputs and Outputs targets which looks to see if the files have been updated,
or if the files are existent. If the files have not been changed, then the Build target is skipped.
-->
<Target Name="Build" Inputs="#(Compile)" Outputs="$(OutputPath)$(AssemblyName).exe" >
<!-- The MakeDir directive will create the directory in the property group above, if it meets the
condition stated in the Condition= statement.
-->
<Message Text="Creating the output path $(OutputPath)." />
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<!-- This Csc is the .NET C# compiler, which then uses the ItemGroup of collected sources called, Compile
-->
<Message Text="Compiling the source code." />
<Csc Sources="#(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>
</Project>
This is the result from trying to run xbuild, and msbuild.
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>xbuild
XBuild Engine Version 3.3.0.0
Mono, Version 3.3.0.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.
Build started 7/25/2014 2:47:41 PM.
__________________________________________________
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default target(s)):
Target Build:
Created directory "bin\"
Tool C:\mono\Mono-3.2.3\bin\gmcs.bat execution started with arguments: /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
Task "Csc" execution -- FAILED
Done building target "Build" in project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED
Done building project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED
Build FAILED.
Errors:
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj (default targets) ->
(Build target) ->
src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
0 Warning(s)
3 Error(s)
Time Elapsed 00:00:01.5341534
This is the result from the MSBuild run. MSBuild completed successfully, but I imagine that's because MSBuild knows where to look without me having to specify it in the csproj file.
C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>MSBuild
Microsoft (R) Build Engine version 4.0.30319.18408
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 7/25/2014 2:48:04 PM.
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" on node 1 (default targets).
Build:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
Done Building Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:04.36
I don't know what to put into the csproj file to make it load those DLL's that I used in the command line to compile using gmcs. Any clues?
-- EDIT 2014-08-20 --
After using the answer from knocte, I was able to see how the References are added in a csproj file. Its as simple as adding an item group, and adding the References you listed with using in the C# source file.
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Drawing" />
<Reference Include="System" />
</ItemGroup>
This is the manual way to do it if you're building the csproj file manually.
Just use an IDE (MonoDevelop or Visual Studio) to add a GAC-reference to System.Windows.Forms and System.Drawing libraries.
I'm trying to create a MSBuild script that could build a VB project and an InstallShield Setup project.
Here's a BuildAll.XML file as the MSBuild script:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<MSBuild Projects="D:\WindowsApplication1\WindowsApplication1\WindowsApplication1.vbproj" />
<MSBuild Projects="D:\WindowsApplication1\Setup1\Setup1.isproj" />
</Target>
</Project>
Running this command on the Developer Command Prompt for VS2012.
msbuild.exe D:\WindowsApplication1\WindowsApplication1\BuildAll.xml /t:Build
The first MSBuild for the WindowApplication1.vbproc completes the build, but when the MSBuild would try to build the Setup1.isproj it fails.
Here's the warning and error:
"D:\WindowsApplication1\WindowsApplication1\BuildAll.xml" (Build
target) ( 1) -> "D:\WindowsApplication1\Setup1\Setup1.isproj" (default
target) (3) -> (Build target) -> C:\Program Files
(x86)\MSBuild\InstallShield\2013Limited\InstallShield.target s :
warning : -7235: InstallShield could not create the software
identification tag because the Tag Creator ID setting in the General
Information view is empt y.
[D:\WindowsApplication1\Setup1\Setup1.isproj] C:\Program Files
(x86)\MSBuild\InstallShield\2013Limited\InstallShield.target s :
warning : -1527: No files are included in the project. [D:\WindowsAppl
ication1\Setup1\Setup1.isproj]
"D:\WindowsApplication1\WindowsApplication1\BuildAll.xml" (Build
target) ( 1) -> "D:\WindowsApplication1\Setup1\Setup1.isproj" (default
target) (3) -> (Build target) -> C:\Program Files
(x86)\MSBuild\InstallShield\2013Limited\InstallShield.target s(108,3):
error : No outputs for project "WindowsApplication1" were provided, b
ut the installation project references
"WindowsApplication1.ContentFiles". [D:\
\WindowsApplication1\Setup1\Setup1.isproj] C:\Program Files
(x86)\MSBuild\InstallShield\2013Limited\InstallShield.target s(108,3):
error : No outputs for project "WindowsApplication1" were provided, b
ut the installation project references "WindowsApplication1.Built".
[D:\WindowsApplication1\Setup1\Setup1.isproj]
The Setup1 Project has two Application Files:
WindowsApplication1.ContentFiles
WindowsApplication1.PrimaryOutput
But when I use the Build > Build Solution on the Visual Studio 2012, it works fine. It produces the Setup.exe.
How can I make my BuildAll.xml make the same building process with the Visual Studio's Build Solution?
Got my answer from this post.
I should have built the entire solution rather than per project
Here's the correct script:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<MSBuild Projects="D:\WindowsApplication1\WindowsApplication1.sln" />
</Target>
</Project>
In Visual Studio 2012 I was running the following Post-Build task to compile and combine my LESS files:
$(MSBuildBinPath)\msbuild.exe "$(ProjectDir)MSBuildSettingsLess.xml"
With my MSBuildSettingsLess.xml looking like:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
<Target Name="CompileDotlessCss">
<ItemGroup>
<Binaries Include="*.dll;*.exe"/>
</ItemGroup>
<!-- Compile dotLess CSS into minified full CSS -->
<Exec Command="$(SolutionDir)..\Tools\dotless.compiler.exe $(ProjectDir)..\GMHC\Content\less\responsive.less $(ProjectDir)..\GMHC\Content\bootstrap-responsive.less.css"/>
<Exec Command="$(SolutionDir)..\Tools\dotless.compiler.exe $(ProjectDir)..\GMHC\Content\less\bootstrap.less $(ProjectDir)..\GMHC\Content\bootstrap.less.css"/>
</Target>
</Project>
In Visual Studio 2013, that fails with the following error:
The command "C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe "C:\Users\Administrator\Documents\Projects\MedicalMissions\GMHC\MSBuildSettingsLess.xml exited with code 9009.
The output windows shows the following:
1> 'C:\Program' is not recognized as an internal or external command,
1> operable program or batch file.
1> C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4429,5): error MSB3073: The command "C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe "C:\Users\Administrator\Documents\Projects\MedicalMissions\GMHC\MSBuildSettingsLess.xml"
Any idea why it is failing or how to get to the bottom of it?
The answer was actually pretty simple, I just had to surround the call in quotes. So the new Post-Build task is:
"$(MSBuildBinPath)\msbuild.exe" "$(ProjectDir)MSBuildSettingsLess.xml"
Looks like it is backward compatible with VS 2012 as well.
You may need quotes in your msbuild defintion (.proj) file.
Generic example:
<Exec Command=""c:\Folder With Spaces\myfile.exe""/>
The same problem occurred for me but i am using space in folder. The solution is working when i remove the space.
Do:
D:\MyDetailsMuthuvelF\Project_Document\
Don't:
D:\My Details Muthuvel F\Project_Document\
When I run MSDeploy from a build script, I get this NullReferenceException. The funny thing is, the project deploys. This has been driving me crazy. Note: This is a web site project, not a web application project.
I'm using this in my build targets file:
<ItemGroup>
<DeploySource Include="DirPath">
<Path>C:\TFS\MySiteBranch\PrecompiledWeb\Source</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</DeploySource>
</ItemGroup>
<ItemGroup>
<TestDeployDest Include="DirPath">
<Path>C:\TFS_Build\POC\Test</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</TestDeployDest>
</ItemGroup>
<Target name="Deploy">
<PropertyGroup>
<WhatIf Condition="'$(WhatIf)'==''">false</WhatIf>
<MSDeployPath Condition="'$(MSDeployPath)'==''">C:\Program Files\IIS\Microsoft Web Deploy V2</MSDeployPath>
</PropertyGroup>
<MSDeploy Condition="'#(TestDeployDest)'!=''"
Whatif="$(WhatIf)"
Verb="sync"
Source="#(DeploySource)"
Destination="#(TestDeployDest)"
ExePath="$(MSDeployPath)"
/>
</target>
Here's the error:
"C:\TFS\MySiteBranch\Source\source.csproj" (Deploy target) (1) ->
(Deploy target) ->
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: The "MSDeploy" task failed unexpectedly.\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Web.Publishing.Tasks.Common.Utility.MsDeployEndOfExecuteMessage(Boolean bSuccess, String destType, String destRoot, TaskLoggingHelper Log)\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Web.Publishing.Tasks.MSDeploy.Execute()\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutio
Any ideas for something I can try?
Try using ContinueOnError="true" on the MSDeploy Elements as the following code:
<ItemGroup>
<DeploySource Include="DirPath">
<Path>C:\TFS\MySiteBranch\PrecompiledWeb\Source</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</DeploySource>
</ItemGroup>
<ItemGroup>
<TestDeployDest Include="DirPath">
<Path>C:\TFS_Build\POC\Test</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</TestDeployDest>
</ItemGroup>
<Target name="Deploy">
<PropertyGroup>
<WhatIf Condition="'$(WhatIf)'==''">false</WhatIf>
<MSDeployPath Condition="'$(MSDeployPath)'==''">C:\Program Files\IIS\Microsoft Web Deploy V2</MSDeployPath>
</PropertyGroup>
<MSDeploy ContinueOnError="true" Condition="'#(TestDeployDest)'!=''"
Whatif="$(WhatIf)"
Verb="sync"
Source="#(DeploySource)"
Destination="#(TestDeployDest)"
ExePath="$(MSDeployPath)"
/>
</target>
I had the same issue; and was just able to address it using the fix described here:
http://forums.iis.net/p/1187159/2016131.aspx#2016131
For me, using the VSMSDeploy task is not an option, as we run x64 servers and web apps. Visual Studio only runs x86 versions of msbuild and msdeploy, and so VSMSDeploy only works for x86 servers and sites. I'm using the appHostConfig provider to store IIS config, and appHostConfig can't sync an x64 site to an x86 instance of msdeploy.
I just ran into the same thing. I wasn't able to figure out what the problem was, but I was able to work around it by using VSMSDeploy instead of MSDeploy. Both tasks are in the same DLL and there are examples of using it in Microsoft.Web.Publishing.targets.
I was able to get the deploy working with a Web Deploy Project.