Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Arkade · Jan 03, 2015 at 02:03 PM · visualstudiounityvs

Prevent UnityVS continually re-writing VS project files (e.g. "target framework")

How can one have UnityVS keep changes made manually to the project files? (I'm using "UnityVS 2015 preview" with "VS 1025 Ultimate preview" btw in case it's relevant.)

Details:

I'm using a Unity asset "Snowify" (excellent, btw) which is supplied as a DLL. I get the following error when I try to compile in UnityVS:

Show Details Severity Code Description File Line Project

Warning The primary reference "SnowCreator" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework. UnityVS.SnowmanScuffle.CSharp.Editor

Error CS0246 The type or namespace name 'SnowCreator' could not be found (are you missing a using directive or an assembly reference?) Snowify.cs 34 UnityVS.SnowmanScuffle.CSharp.Editor

To resolve, I have a painful manual process that requires re-doing every compile:

  • Find and right click Editor project | properties

  • change target framework to ".NET Framework 4"

  • save

  • compile

  • ...

  • but as soon as I visit Unity Editor (or even before sometimes), it re-writes the project file and requires it be reloaded! (declining reload causes another problem -- vaguely recall it seemed the change had been partially loaded? Can investigate if necessary.)

The only potential answer I've found so far is to write a project file generator that makes the change I want manually = a pain. (yes, I was inspired by How can I make Unity open MonoDevelop with a target framework of .NET 4.0 instead of 3.5?.)

Hope I'm not missing something obvious -- I'm new to UnityVS (and VS). I've unticked "Generate solution file" and "Generate mdb files" but no luck.

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Arkade · Jan 04, 2015 at 10:57 PM

Decided to bite the bullet and write a ProjectFileGeneration util. Works. Here it is for anyone else who runs into the same problem:

 using System;
 using System.IO;
 using System.Linq;
 using System.Text;
 using System.Xml.Linq;
 
 using UnityEngine;
 using UnityEditor;
 
 using SyntaxTree.VisualStudio.Unity.Bridge;
 
 namespace Assets.UGS.UnityUtils {
 
     /// <summary>
     /// Modify Editor project file generation to use <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>.
     /// Based on http://unityvs.com/documentation/api/project-file-generation/ 
     /// </summary>
     [InitializeOnLoad]
     class UnityVSProjectFileHook {
 
         // necessary for XLinq to save the xml project file in utf8
         class Utf8StringWriter : StringWriter {
             public override Encoding Encoding {
                 get { return Encoding.UTF8; }
             }
         }
 
         static UnityVSProjectFileHook() {
             ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) => {
                 Debug.Log(string.Format("{0} starting on \"{1}\"", typeof(UnityVSProjectFileHook).Name, name));
                 var document = XDocument.Parse(content);                    
                 var assemblyName = document.Descendants(XName.Get(ASSEMBLY_NAME, SCHEMA)).FirstOrDefault();
                 if (null != assemblyName && assemblyName.Value.Contains(ASSEMBLY_CSHARP_EDITOR)) {
                     var target = document.Descendants(XName.Get(TARGET_FRAMEWORK_VERSION, SCHEMA)).FirstOrDefault();
                     if (null != target && target.Value.Contains(FRAMEWORK_EXPECTED)) {
                         target.SetValue(FRAMEWORK_DESIRED);
                         Debug.Log(string.Format("{0} set \"{1}\"'s {2} to \"{3}\"", typeof (UnityVSProjectFileHook).Name, name, TARGET_FRAMEWORK_VERSION, FRAMEWORK_DESIRED));
                     }
                     var targetProfile = document.Descendants(XName.Get(TARGET_FRAMEWORK_PROFILE, SCHEMA)).FirstOrDefault();
                     if (null != targetProfile && targetProfile.Value.Contains(PROFILE_EXPECTED)) {
                         targetProfile.SetValue(PROFILE_DESIRED);
                         Debug.Log(string.Format("{0} set \"{1}\"'s {2} to \"{3}\"", typeof(UnityVSProjectFileHook).Name, name, TARGET_FRAMEWORK_PROFILE, PROFILE_DESIRED));
                     }
                 }
                 var str = new Utf8StringWriter();
                 document.Save(str);
 
                 return str.ToString();
             };
         }
 
         private const string SCHEMA = @"http://schemas.microsoft.com/developer/msbuild/2003";
         private const string ASSEMBLY_NAME = "AssemblyName";
         private const string ASSEMBLY_CSHARP_EDITOR = "Assembly-CSharp-Editor";
         private const string TARGET_FRAMEWORK_VERSION = "TargetFrameworkVersion";
         private const string TARGET_FRAMEWORK_PROFILE = "TargetFrameworkProfile";
         private const string FRAMEWORK_EXPECTED = "v3.5";
         private const string FRAMEWORK_DESIRED = "v4.0";
         private const string PROFILE_EXPECTED = "Unity Full v3.5";
         private const string PROFILE_DESIRED = "";
     }
 
 }
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tswalk · Apr 10, 2015 at 01:49 PM 0
Share

cool trick!

avatar image tswalk · Sep 07, 2015 at 06:55 PM 0
Share

just fyi, as of today (at least)... I was able to add my dependencies to the generated UnityVS solution and have them "stick" to the solution file... but only after I generated my solution in UnityVS options, then disabled "generate solution file". After which, I was able to open the project, add the "existing project" (my dependency plugins), save the solution in Visual Studio (using 2013 update 4 currently), close VS, and reopen via UnityVS in Unity.

perhaps they fixed something somewhere :)

(I'm using Unity 5.1.3p1 & latest UnityVS 2.0.0)

avatar image DarkSlash · Oct 24, 2015 at 03:00 PM 1
Share

Where is supposed to put this file? What are the steps to implement it? Thanks! I have the same issue!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityVS: "This document is opened by another project" when reloading solution 0 Answers

Visual Studio Debugger? UnityVS? 1 Answer

UnityVS debugger freeze Unity 4.5.1 0 Answers

Is it possible for unity to open visual studio as a dumb text editor? 0 Answers

Visual scripting 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges